C program to find the volume of a cylinder - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, June 14, 2019

C program to find the volume of a cylinder

In this tutorial we will find the volume of a cylinder.Whenever we find the volume of ​​a cylinder, then we should know its radius and height for it.

Solution

  • In this program we will use pie, height and radius of a cylinder so we will take four variables as pie,r,h and volume.
  • We declared these variables in float data type.
  • Then we will enter the value of pie radius and height of a cylinder.
  • We use a logic as volume=pie*r*r*h
  • When we use this statement the value of pie, radius and height multiplication of a cylinder will be store in volume variable.
  • Then we will print the volume of cylinder.

We can use two types for calculate the are of circle as

  1. By enter the value of pie.
  2. By constant pie.

C program code - by using constant pie


#include<stdio.h>
#include<conio.h>
void main()
{
const float pie=3.141;
float r;
float h;
float volume;
clrscr();

printf("\n Enter the value of radius=");
scanf("%f",&r);

printf("\n Enter the value of height=");
scanf("%f",&h);

volume=pie*r*r*h;

printf("\n The volume of a cylinder is=");
printf("%f",volume);
getch();
}


Output 1:



Output 2:




C program code - by enter the value of pie


#include<stdio.h>
#include<conio.h>
void main()
{
 float pie;
 float r;
 float h;
 float volume;
 clrscr();

  printf("\n Enter the value of pie=");
 scanf("%f",&pie);

 printf("\n Enter the value of radius=");
 scanf("%f",&r);

 printf("\n Enter the value of height=");
 scanf("%f",&h);

 volume=pie*r*r*h;

 printf("\n The volume of a cylinder is=");
 printf("%f",volume);
 getch();
}


Output 1:




Output 2:



Whenever we find the volume of ​​a cylinder, then we should know its radius and height for it.we can use two types for find the volume of a cylinder.


No comments:

Post a Comment