Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C Articles
Page 47 of 96
C Program to add two fractions
Given with the input as fraction i.e. a/b and c/d where a, b, c and d can be any integer values other than 0 and the task is to add these two fraction to generate their final sum. Fractions are represented by − a / b, where a is known as numerator and b is known as denominator. a and b can have any numeric values but b can have any numeric value other than 0. Sum of two fractions is represented as a / b + c / d, and the rule for adding the two ...
Read MoreC program to calculate distance between two points
Given two points with coordinates, we need to calculate the distance between them. In a two-dimensional plane, if we have points A and B with coordinates (x1, y1) and (x2, y2) respectively, we can find the distance using the Euclidean distance formula. Syntax distance = sqrt((x2 - x1)² + (y2 - y1)²) Distance Formula The distance between two points is calculated using the formula − ...
Read MoreC program to calculate distance between three points in 3D
In C programming, calculating the distance between two points in 3D space is a common geometric problem. The distance between two points in three-dimensional space can be calculated using the Euclidean distance formula. Syntax distance = sqrt(pow(x2-x1, 2) + pow(y2-y1, 2) + pow(z2-z1, 2)); Where (x1, y1, z1) and (x2, y2, z2) are the coordinates of the two points in 3D space. Formula The mathematical formula for calculating distance between two points in 3D space is − Distance = √[(x2-x1)² + (y2-y1)² + (z2-z1)²] ...
Read MoreC program to calculate age
Calculating age is a common programming task that requires handling date arithmetic carefully. This involves computing the difference between two dates while accounting for varying month lengths and leap years. Syntax void calculateAge(int currentDay, int currentMonth, int currentYear, int birthDay, int birthMonth, int birthYear); Algorithm The age calculation follows these steps − If the current day is less than birth day, borrow days from the previous month If the current month is less ...
Read MoreC program to Calculate Body Mass Index (BMI)
Body Mass Index (BMI) is a health metric used to assess whether a person has a healthy body weight relative to their height. In C programming, we can calculate BMI using a simple formula. Syntax BMI = weight / (height * height) Where weight is in kilograms and height is in meters. Example: BMI Calculator This example demonstrates how to calculate BMI using a function − #include // Function to calculate BMI float calculateBMI(float weight, float height) { return weight / (height * height); } ...
Read MoreProgram to convert given number of days in terms of Years, Weeks and Days in C
You are given a number of days, and the task is to convert the given number of days in terms of years, weeks and days. Let us assume the number of days in a year = 365 (non-leap year). Syntax years = total_days / 365 weeks = (total_days % 365) / 7 days = (total_days % 365) % 7 Formula Explanation Number of years = (number of days) / 365 − The quotient obtained by dividing the given number of days with 365 Number of weeks = (number of days % 365) ...
Read MoreImplicit Threading and Language-based threads
Implicit threading is a programming approach where the creation and management of threads is handled by compilers and run-time libraries rather than application developers. This approach simplifies multithreaded programming by abstracting away low-level thread management details. Syntax #pragma omp parallel { // Parallel code block } OpenMP for Implicit Threading OpenMP is a widely-used implicit threading library for C, C++, and FORTRAN. It provides compiler directives and an API for parallel programming in shared-memory environments. OpenMP identifies parallel regions as blocks of code that can execute in parallel − ...
Read MoreWindows thread API in the C program
Threads are created in the Windows API using the CreateThread() function. Just as in Pthreads, a set of attributes like security information, the size of the stack, and a flag for the thread is passed to this function. In the below program, we use the default values for these attributes. Once the summation thread is created, the parent must wait for it to complete before outputting the value of Sum, as the value is set by the summation thread. Using the WaitForSingleObject() function, we perform the equivalent of pthread_join() in the Windows API, which causes the creating thread to ...
Read MoreArc function in C
In C programming, the arc() function is used to draw an arc (a portion of a circle's circumference) on the graphics screen. This function is part of the graphics.h library, which provides various drawing capabilities for creating graphical outputs. Syntax void arc(int x, int y, int startangle, int endangle, int radius); Parameters The arc() function accepts five parameters − x − The x-coordinate of the center of the arc y − The y-coordinate of the center of the arc startangle − The starting angle of the arc in degrees (0-360) endangle − ...
Read MoreGrand Central Dispatch (GCD)
Grand Central Dispatch (GCD) is a technology for Apple's Mac OS X and iOS operating systems that provides a combination of extensions to the C language, an API, and a runtime library. It allows application developers to identify sections of code to run in parallel, managing most of the threading details automatically like OpenMP. Syntax // Block syntax ^{ /* code block */ } // Dispatch queue creation dispatch_queue_t dispatch_get_global_queue(long identifier, unsigned long flags); // Async execution void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); Blocks in GCD GCD introduces extensions to the C and ...
Read More