Coding Practice

Write a C program using three different User Defined Function...

Using User Defined Function (UDF)

Write a C program using three different User Defined Function (UDF) to compute- 1. Volume or 2. Surface Area of a sphere whose radius is given by the user as the input.

Sample Output
Enter the radius(inches): 5

Enter the computation mode:
V: Volumn
A: Area
A

The surface area is (square inches): 314.160


Process returned 0 (0x0)   execution time : 14.521 s
Press any key to continue.
Source Code
#include<stdio.h>
#include<math.h>
 
float pi = 3.1416;
 
int volumn(float radius)
{
    float V;
    V = (1.33333 * pi * pow(radius, 3));
 
    printf("\nThe volume is (square inches): %.3f\n\n", V);
}
 
int area(float radius)
{
    float A;
    A = 4 * pi * pow(radius, 2);
    printf("\nThe surface area is (square inches): %.3f\n\n", A);
}
 
int main()
{
    float radius;
    char option;
 
    printf("Enter the radius(inches): ");
    scanf("%f", &radius);
 
    printf("\nEnter the computation mode:\nV: Volumn\nA: Area\n");
    scanf(" %c", &option);
 
    switch(option)
    {
    case 'V':
    case 'v':
        volumn(radius);
        break;
 
    case 'A':
    case 'a':
        area(radius);
        break;
 
    default:
        printf("Invalid mode!");
        break;
    }
    return 0;
}
Sample Output
Enter the radius(inches): 5

Enter the computation mode:
V: Volumn
A: Area
A

The surface area is (square inches): 314.160


Process returned 0 (0x0)   execution time : 14.521 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X