C Program To Find Area and Circumference of Circle using Pointer

Lets write a C program to calculate area and circumference or perimeter of a Circle using pointer and function.

Related Read:
Function / Methods In C Programming Language
Basics of Pointers In C Programming Language

Video Tutorial: C Program To Find Area and Circumference of Circle using Pointer


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

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


Source Code: C Program To Find Area and Circumference of Circle using Pointer

#include<stdio.h>

void area_peri(float, float*, float*);

int main()
{
    float radius, area, perimeter;

    printf("Enter radius of Circle\n");
    scanf("%f", &radius);

    area_peri(radius, &area, &perimeter);

    printf("\nArea of Circle = %0.2f\n", area);
    printf("Perimeter of Circle = %0.2f\n", perimeter);

    return 0;
}

void area_peri(float r, float *a, float *p)
{
    *a = 3.14 * r * r;
    *p = 2 * 3.14 * r;
}

Output 1:
Enter radius of Circle
5

Area of Circle = 78.50
Perimeter of Circle = 31.40

Output 2:
Enter radius of Circle
14

Area of Circle = 615.44
Perimeter of Circle = 87.92

Logic To Find Area and Circumference of Circle using Pointer

We ask the user to enter value for radius of a Circle. We pass this value along with address of variables area and perimeter to the function area_peri().

area_peri(radius, &area, &perimeter);

We copy the value of radius to a local variable r and then we take 2 floating point pointer variables *a and *p. *a represents the value present at address a or &area. *p has value present at address p or &perimeter.

Inside area_peri() function we calculate the area and circumference / perimeter of Circle and store it as value present at addresses a and p. Since a points to address of variable area and p points to address of variable perimeter, the values of variable area and perimeter changes too.

*a = 3.14 * r * r;

*p = 2 * 3.14 * r;

Area and Circumference of Circle

We’ve separate video tutorials to calculate area and circumference of a Circle using radius, and without using pointer and function. You can check them out at these links:

Calculate Area of a Circle without using math.h library: C
C Program To Calculate Circumference of Circle

Note: When * is precedes any address, it fetches the value present at that address or memory location.

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

C Program To Calculate Volume of Cone

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

Formula To Calculate Volume of Cone

volume = ( Base_Area x height ) / 3.0;

Base of the Cone is a Circle. Area of Circle is PI x Radius2

So lets replace Base_Area with Area of Circle: PI x Radius2.

Therefore, volume = ( (PI x Radius2) x height ) / 3.0;

volume of Cone

where PI is approximately equal to 3.14159265359;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

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

Output:
Volume of Cone is 20.933334

Logic To Calculate Volume of Cone

We ask the user to enter values for radius and height of the Cone. If user enters 2m and 5m. Then we use the formula to calculate the Volume of Cone:

volume = (PI x Radius2 x height) / 3.0;

User input:
radius = 2m;
height = 5m;

PI value is 3.14159265359;

volume = ( PI x Radius2 x height ) / 3.0;
volume = ( 3.14 x (2m)2 x (5m) ) / 3.0;
volume = ( 3.14 x 4(m)2 x 5(m) ) / 3.0;
volume = ( 3.14 x 20 m3 ) / 3.0;
volume = ( ‭62.8 m3 ) / 3.0;
volume = 20.93‬ m3;

So volume of Cone is 20.93 cubic meter.

Video Tutorial: C Program To Calculate Volume of Cone


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

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

Source Code: C Program To Calculate Volume of Cone

#include<stdio.h>

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

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

    volume = (PI * r * r * h) / 3.0;

    printf("Volume of Cone is %f\n", volume);

    return 0;
}

Output 1:
Enter radius and height of the cone
8
18
Volume of Cone is 1205.760010

Output 2:
Enter radius and height of the cone
5
14
Volume of Cone is 366.333344

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 Sphere

Given the value for radius of a Sphere, write a C program to calculate Surface Area of the Sphere.

Formula To Calculate Surface Area of Sphere

When radius value is known: Area = 4 * π * radius²,
When diameter value is known: Area = π * diameter²,
When volume value is known: Area = ³√(36 * π * Volume²).

where π (PI) is approximately equal to 3.14

surface area of sphere

Related Read:
Basic Arithmetic Operations In C

Logic To Calculate Surface Area of Sphere

We ask the user to enter the value of radius of the sphere. We apply the formula:
Surface_ Area = 4 * PI * radius2
where π (PI) is approximately equal to 3.14

Expected Output for the Input

User Input:
Enter Radius of the Sphere
5

Output:
Surface Area of Sphere is 314.000000

Video Tutorial: C Program To Calculate Surface Area of Sphere


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

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

Source Code: C Program To Calculate Surface Area of Sphere

#include<stdio.h>

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

    printf("Enter Radius of the Sphere\n");
    scanf("%f", &r);

    area = ( 4 * PI * r * r );

    printf("Surface Area of Sphere is %f\n", area);

    return 0;
}

Output 1:
Enter Radius of the Sphere
2
Surface Area of Sphere is 50.240002

Output 2:
Enter Radius of the Sphere
10
Surface Area of Sphere is 1256.000000

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 Volume of Sphere

Given the value for radius of a Sphere, write a C program to calculate volume of the Sphere.

Formula To Calculate Volume of Sphere

volume = ( 4 * PI * radius3 ) / 3.0;

OR

volume = ( 1.333 * PI * radius3 );

volume of sphere

where PI is approximately equal to 3.14;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter Radius of the Sphere
5

Output:
Volume of Sphere is 523.333374

Logic To Calculate Volume of Sphere

We ask the user to enter value for radius of the Sphere. If user enters 5 inche. Then we use the formula to calculate the Volume of Sphere:

volume = ( 4 * PI * radius3 ) / 3.0;

User input:
radius = 5 inches;

PI value is approximately equal to 3.14;

volume = ( 4 * PI * radius3 ) / 3.0
volume = ( 4 * 3.24 * (5 inches)3) / 3.0
volume = ( ‭12.56‬ * 125 inches3 ) / 3.0
volume = ( ‭12.56‬ * 125 inches3 ) / 3.0
volume = ‭1,570‬ inches3 / 3.0
volume = ‭523.33 inches3

Video Tutorial: C Program To Calculate Volume of Sphere


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

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

Source Code: C Program To Calculate Volume of Sphere

#include<stdio.h>

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

    printf("Enter Radius of the Sphere\n");
    scanf("%f", &r);

    volume = ( 4 * PI * r * r * r ) / 3.0;

    printf("Volume of Sphere is %f\n", volume);

    return 0;
}

Output 1:
Enter Radius of the Sphere
3
Volume of Sphere is 113.040001

Output 2:
Enter Radius of the Sphere
14
Volume of Sphere is 11488.213867

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