Found 1401 Articles for C

C Program to add two fractions

Sunidhi Bansal
Updated on 18-Oct-2019 12:26:44

3K+ Views

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 terms is that their denominator must be ... Read More

C program to calculate distance between two points

Sunidhi Bansal
Updated on 18-Oct-2019 11:10:35

3K+ Views

Given with the two points coordinates and the task is to find the distance between two points and display the result.In a two dimension plane there are two points let’s say A and B with the respective coordinates as (x1, y1) and (x2, y2) and to calculate the distance between them there is a direct formula which is given below$$\sqrt{\lgroup x2-x1\rgroup^{2}+\lgroup y2-y1\rgroup^{2}}$$Given below is the diagram representing two points and their differences$$\frac{(x_2-x_1)}{(x_1, y_1)\:\:\:\:\:\:(y_2-y_1)\:\:\:\:\:\:(x_2, y_2)}$$Approach used below is as follows −Input the coordinates as x1, x2, y1 and y2Apply the formula to compute the difference between two pointsPrint the distanceAlgorithmStart Step ... Read More

C program to calculate distance between three points in 3D

Sunidhi Bansal
Updated on 18-Oct-2019 11:02:39

801 Views

Given with the 3-D plane and hence three coordinates and the task is to find the distance between the given points and display the result.In a three dimension plane there are three axis that are x-axis with its coordinates as (x1, y1, z1), y-axis with its coordinates as (x2, y2, z2) and z-axis with its coordinates as (x3, y3, z). To calculate the distance between them there is a direct formula which is given below$$\sqrt{\lgroup x2-x1\rgroup^{2}+\lgroup y2-y1\rgroup^{2}+\lgroup z2-z1\rgroup^{2}}$$Given below is the diagram representing three different axis and their coordinatesApproach used below is as follows −Input the coordinates as (x1, y1, ... Read More

C program to calculate age

Sunidhi Bansal
Updated on 18-Oct-2019 10:57:19

22K+ Views

Given with the current date and the birth date of a person and the task is to calculate his current age.ExampleInput-: present date-: 21/9/2019    Birth date-: 25/9/1996 Output-: Present Age    Years: 22 Months:11 Days: 26Approach used below is as follows −Input the current date and birth date of a personCheck for the conditionsIf current month is less than the birth month, then we will not consider the current year because this year has not been completed yet and to compute the differences in months by adding 12 to the current month.If the current date is less than the ... Read More

C program to Calculate Body Mass Index (BMI)

Sunidhi Bansal
Updated on 18-Oct-2019 09:15:50

8K+ Views

Given with the weight and height of a person and the task is to find the BMI i.e. body mass index of his body and display it.For calculating the body mass index we require two things −WeightHeightBMI can be calculated using the formula given below −BMI = (mass or weight) / (height*height)Where weight is in kg and height is in metersExampleInput 1-: weight = 60.00    Height = 5.1 Output -: BMI index is : 23.53 Input 2-: weight = 54.00    Height = 5.4 Output -: BMI index is : 9.3Approach used below is as follows −Input weight(kg) and ... Read More

Program for Fahrenheit to Celsius conversion in C

Sunidhi Bansal
Updated on 18-Oct-2019 08:25:55

697 Views

Given with temperature ‘n’ in Fahrenheit and the challenge is to convert the given temperature to Celsius and display it.ExampleInput 1-: 132.00 Output -: after converting fahrenheit 132.00 to celsius 55.56 Input 2-: 456.10 Output -: after converting fahrenheit 456.10 to celsius 235.61For converting the temperature from Fahrenheit to Celsius, there is a formula which is given belowT(°C) = (T(°F) - 32) × 5/9Where, T(°C) is temperature in Celsius and T(°F) is temperature in FahrenheitApproach used below is as follows −Input temperature in a float variable let’s say FahrenheitApply the formula to convert the temperature into CelsiusPrint celsiusAlgorithmStart Step 1-> ... Read More

Program to convert given number of days in terms of Years, Weeks and Days in C

Sunidhi Bansal
Updated on 18-Oct-2019 07:51:37

3K+ Views

You are given with 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 =365Number of year = (number of days) / 365Explanation-: number of years will be the quotient obtained by dividing the given number of days with 365Number of weeks = (number of days % 365) / 7Explanation-: number of weeks will be obtained by collecting the remainder from dividing the number of days with 365 and further dividing the result with number of days in a week ... Read More

POSIX Thread Libraries

Arnab Chakraborty
Updated on 17-Oct-2019 08:49:29

787 Views

Pthreads refers to the POSIX standard (IEEE 1003.1c) defining an API for thread creation and synchronization. This defines specification for thread behavior, not an implementation. The specification can be implemented by OS designers in any way they wish. So many systems implement the Pthreads specification; most are UNIX-type systems, including Linux, Mac OS X, and Solaris. Although Windows doesn’t support Pthreads natively, some third-party implementations for Windows are available. The C program shown in Figure 4.9 demonstrates the basic Pthreads API for constructing a multithreaded program that calculates the summation of a nonnegative integer in a separate thread. Separate threads ... Read More

Implicit Threading and Language-based threads

Arnab Chakraborty
Updated on 17-Oct-2019 08:46:49

3K+ Views

Implicit ThreadingOne way to address the difficulties and better support the design of multithreaded applications is to transfer the creation and management of threading from application developers to compilers and run-time libraries. This, termed implicit threading, is a popular trend today.Implicit threading is mainly the use of libraries or other language support to hide the management of threads. The most common implicit threading library is OpenMP, in context of C.OpenMP is a set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments. OpenMP identifies ... Read More

Windows thread API in the C program

Arnab Chakraborty
Updated on 16-Oct-2019 10:39:12

2K+ Views

Threads are created in the Windows API using the CreateThread() function, and—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. (The default values do not initially set the thread to a suspended state and instead make it eligible to be run by the CPU scheduler.) 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 ... Read More

Advertisements