Computer Science, asked by exammonster, 2 months ago

Write a program to find and display the volume of a sphere, and a cylinder with the following formulas: ​
volume of a sphere​=4/3πr2
volume of a cylinder​=πr2h

Answers

Answered by miskatmfa
0

Answer:

Explanation:

A) Answer-

#include <stdio.h>

float myradius;          /* radius of the sphere */

float myvolume;          /* volume of the sphere (to be computed) */

char line_text[50];      /* a line from the keyboard */

/* the value of pi to 50 places, from wikipedia */

const float PI = 3.14159265358979323846264338327950288419716939937510;

int main() {

printf("Input the radius of the sphere : ");

fgets(line_text, sizeof(line_text), stdin);

sscanf(line_text, "%f", &myradius);

myvolume = (4.0 / 3.0) * PI * (myradius * myradius * myradius);  /* volumn=(4/3) * pi * r^3*/

printf("The volume of sphere is %f.\n", myvolume);

return(0);

}

Output-

Input the radius of the sphere : 2.56                                                                          

The volume of sphere is 70.276237.

B) Answer-

int main()

{

 

float vol,r,h;

printf("enter radius: ");

scanf("%f",&r);

printf("enter height: ");

scanf("%f",&h);

   

vol=(22*r*r*h)/7;

printf("VOC: %f\n",vol);

return 0;

}

output:

enter radius: 7

enter height: 7

VOC: 1078.000000

Similar questions
Math, 9 months ago