QwertyManiac
Commander in Chief
Re: Post ur C/C++ Programs Here
Resulting I/O:
There, homework done. :\
Code:
#include <stdio.h>
#include <math.h>
#include<stdlib.h>
#define PI 3.1416
float radius(float d) { return d/2; }
float surface(float d) { return 4*PI*pow(d/2,2); }
float circum(float d) { return PI*d; }
float volume(float d) { return (4*PI*pow(d/2,3))/3; }
int main(int argc, char **argv)
{
float dia;
printf("Enter the diameter: ");
scanf("%f",&dia);
dia<0.0?exit(1):printf("\nDiameter: %f", dia);
printf("\nRadius is: %f", radius(dia));
printf("\nSurface Area is: %f", surface(dia));
printf("\nCircumference is: %f", circum(dia));
printf("\nVolume is: %f\n", volume(dia));
return 0;
}
Resulting I/O:
Code:
Enter the diameter: 4
Radius is: 2.000000
Surface Area is: 50.265598
Circumference is: 12.566400
Volume is: 33.510399
There, homework done. :\
Last edited: