C Program To Convert Pounds to Kilograms

Lets write a C program to Convert weight from Pounds to Kilograms.

Note: 1 Pound is approximately equal to 0.453592 Kilogram.

pound to kilogram

Formula To Convert Weight From Pounds to Kilograms

kilogram = pound * 0.453592;

OR

From our previous video tutorial C Program To Convert Kilograms to Pounds

pound = kilogram * 2.20462;
pound / 2.20462 = kilogram;
kilogram = pound / 2.20462;

Related Read:
Keywords, Constants, Variables: C
Basic Arithmetic Operations In C

Logic To Convert Pounds to Kilograms

First we ask the user to enter weight / mass in pounds. Then we multiply that value with 0.453592. The result itself is the Kilograms equivalent of user entered weight in pound.

Video Tutorial: C Program To Convert Pounds to Kilograms


[youtube https://www.youtube.com/watch?v=-MmRvZ538f4]

YouTube Link: https://www.youtube.com/watch?v=-MmRvZ538f4 [Watch the Video In Full Screen.]

Source Code: C Program To Convert Pounds to Kilograms

#include<stdio.h>

int main()
{
    const float KG = 0.453592;
          float pound;

    printf("Enter weight in pounds\n");
    scanf("%f", &pound);

    printf("Weight in Kilograms is %f\n", (pound * KG) );

    return 0;
}

Output 1:
Enter weight in pounds
11
Weight in Kilograms is 4.989512

Output 2:
Enter weight in pounds
11.04
Weight in Kilograms is 5.007656

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Convert Kilograms to Pounds

Lets write a C program to Convert weight from Kilograms to Pounds.

Note: 1 Kilogram is approximately equal to 2.20462 Pound.

kilogram to pound

Formula To Convert Weight From Kilograms to Pounds

pound = kilogram * 2.20462;

Related Read:
Keywords, Constants, Variables: C
Basic Arithmetic Operations In C

Logic To Convert Kilograms to Pounds

First we ask the user to enter weight / mass in kilograms. Then we multiply that value with 2.20462. The result itself is the pound equivalent of user entered weight in KG.

Video Tutorial: C Program To Convert Kilograms to Pounds


[youtube https://www.youtube.com/watch?v=puxuafYkOh0]

YouTube Link: https://www.youtube.com/watch?v=puxuafYkOh0 [Watch the Video In Full Screen.]

Source Code: C Program To Convert Kilograms to Pounds

#include<stdio.h>

int main()
{
    const float POUND = 2.20462;
    float kg;

    printf("Enter weight in Kilograms\n");
    scanf("%f", &kg);

    printf("Weight in Pounds is %f\n", (kg * POUND));

    return 0;
}

Output 1:
Enter weight in Kilograms
5
Weight in Pounds is 11.023099

Output 2:
Enter weight in Kilograms
14
Weight in Pounds is 30.864678

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Percentage Difference Between 2 Numbers

Given two numbers, write a C program to calculate percentage difference between those two numbers.

Formula To Calculate Percentage Difference Between Two Numbers

If user entered numbers are stored in variables a and b. Then the formula to calculate the percentage difference between a and b is:

result = ( |a-b| / ((a+b) / 2.0) ) * 100;

OR

result = ( abs(a-b) / ((a+b) / 2.0) ) * 100;

Note: abs() is a builtin method present in stdlib.h header file, which returns the absolute value.

Related Read:
Basic Arithmetic Operations In C

Check this video tutorial to know more about absolute value:
C Program To Find Absolute Value of a Number

Logic To Calculate Percentage Difference Between 2 Numbers

The percentage difference between two numbers is calculated by dividing the absolute value of the difference between two numbers by the average of those two numbers. And then multiplying the result by 100.

Expected Output for the Input

User Input:
Enter 2 numbers
100
200

Output:
Percentage difference is 66.666664

Video Tutorial: C Program To Calculate Percentage Difference Between 2 Numbers


[youtube https://www.youtube.com/watch?v=L7Vc7-1z9os]

YouTube Link: https://www.youtube.com/watch?v=L7Vc7-1z9os [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Percentage Difference Between 2 Numbers

#include<stdio.h>
#include<stdlib.h>

int main()
{
    float a, b, result;

    printf("Enter 2 numbers\n");
    scanf("%f%f", &a, &b);

    result = ( abs(a-b) / ( (a+b)/2.0 ) ) * 100;

    printf("Percentage difference is %f\n", result);

    return 0;
}

Output 1:
Enter 2 numbers
50
60
Percentage difference is 18.181818

Output 2:
Enter 2 numbers
60
50
Percentage difference is 18.181818

Output 3:
Enter 2 numbers
75
75
Percentage difference is 0.000000

Output 4:
Enter 2 numbers
75
100
Percentage difference is 28.571428

Output 5:
Enter 2 numbers
150
200
Percentage difference is 28.571428

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Distance Between Two Points

Given two points A(x1, y1) and B(x2, y2), find the distance between them.

Formula To Calculate Distance Between Two Points using Pythagorean theorem

distance = sqrt( (x2 – x1) * (x2 – x1) + (y2 – y1) * (y2 – y1) );

Note: sqrt() is a builtin method present in math.h header file.

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter point 1 (x1, y1)
1
1
Enter point 2 (x2, y2)
9
9

Output:
Distance between (1.00, 1.00) and (9.00, 9.00) is 11.31

Video Tutorial: C Program To Calculate Distance Between Two Points


[youtube https://www.youtube.com/watch?v=e4R-VhXp_k4]

YouTube Link: https://www.youtube.com/watch?v=e4R-VhXp_k4 [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Distance Between Two Points

#include<stdio.h>
#include<math.h>

int main()
{
    float x1, y1, x2, y2, distance;

    printf("Enter point 1 (x1, y1)\n");
    scanf("%f%f", &x1, &y1);

    printf("Enter point 2 (x2, y2)\n");
    scanf("%f%f", &x2, &y2);

    distance = sqrt( (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1) );

    printf("Distance between (%0.2f, %0.2f) and (%0.2f, %0.2f) is %0.2f\n", x1, y1, x2, y2, distance);

    return 0;
}

Output 1:
Enter point 1 (x1, y1)
0
0
Enter point 2 (x2, y2)
5
0
Distance between (0.00, 0.00) and (5.00, 0.00) is 5.00

Output 2:
Enter point 1 (x1, y1)
2
3
Enter point 2 (x2, y2)
10
8
Distance between (2.00, 3.00) and (10.00, 8.00) is 9.43

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Program To Calculate Surface Area of Cone

Given the values for radius and height of a Cone, write a C program to calculate Surface Area of the Cone.

Formula To Calculate Surface Area of Cone

Surface_Area = PI * radius * (radius + sqrt(height * height + radius * radius ));
where PI is approximately equal to 3.14

Note: sqrt() is a builtin method present in math.h header file.

surface area of cone

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter radius and height of the cone
2
5

Output:
Surface Area of Cone is 46.378838

Video Tutorial: C Program To Calculate Surface Area of Cone


[youtube https://www.youtube.com/watch?v=yqKdKmSBtG0]

YouTube Link: https://www.youtube.com/watch?v=yqKdKmSBtG0 [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Surface Area of Cone

#include<stdio.h>
#include<math.h>

int main()
{
    const float PI = 3.14;
          float r, h, s_area;

    printf("Enter radius and height of the cone\n");
    scanf("%f%f", &r, &h);

    s_area = PI * r * ( r + sqrt(h * h + r * r) );

    printf("Surface Area of Cone is %f\n", s_area);

    return 0;
}

Output 1:
Enter radius and height of the cone
8
18
Surface Area of Cone is 695.766663

Output 2:
Enter radius and height of the cone
5
14
Surface Area of Cone is 311.897278

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert