In C Language using \"#Include <stdio.h>\". Write a program to produce a cube. I
ID: 2268275 • Letter: I
Question
In C Language using "#Include <stdio.h>".
Explanation / Answer
//Program for cube
#include <stdio.h>
int main()
{
float length;
//Program to produce the cube
printf("Enter the length of a side of cube ");
scanf("%f",&length);
printf("The area of base of cube is %f ", length*length);
printf("The surface area of the cube is %f ",6*length*length);
printf("The volume of the cube is %f ",length*length*length);
}
//Program for cylinder
#include <stdio.h>
int main()
{
float radius, height;
float pi = 3.14; //constant
printf("Enter the radius and height of the cylinder ");
scanf("%f %f",&radius,&height);
printf("The area of base of cylinder is %f ",(pi*radius*radius));
printf("The surface area of the cylinder is %f ",(2*pi*radius*(radius+height)));
printf("The volume of cylinder is %f ",(pi*radius*radius*height));
return 0;
}
//Program for square pyramid
#include <stdio.h>
int main()
{
float length,height,surfacearea,volume,base_area;
float pi = 3.14; //constant
printf("Enter the side length base and height of the square pyramid ");
scanf("%f %f",&length,&height);
printf("The side length of base is %f and height is %f ",length,height);
base_area = length*length;
printf("The area of base of pyramid is %f ",base_area);
surfacearea = length*length + 2*length*sqrt(((length*length)/4)+height*height);
printf("The surface area of the pyramid is %f ",surfacearea);
volume = length*length*height/3;
printf("The volume of pyramid is %f ",volume);
return 0;
}