Header Ads Widget

Mathematical Program in C

 1. Find the Area of Circle


/* C Program to Calculate Area Of a Circle using Radius */

#include<stdio.h>

#define PI 3.14

main()
{
  float radius, area, circumference;

  printf("\n Please Enter the radius of a circle\n");
  scanf("%f",&radius);

  area = PI*radius*radius; 
  circumference = 2* PI*radius;

  printf("\n Area Of a Circle = %.2f\n", area);
  printf("\n Circumference Of a Circle = %.2f\n", circumference);

  return 0;
}


Output :-


Please Enter the radius of a circle :
25
Area Of a Circle = 1962.50

 Circumference Of a Circle = 157.00



2. Find the Area of Triangle



/* C Program to find Area of a Triangle and Perimeter of a Triangle */

#include<stdio.h>
#include<math.h>

int main()
{
  float a, b, c, Perimeter, s, Area;
  
  printf("\nPlease Enter three sides of triangle\n");
  scanf("%f%f%f",&a,&b,&c);
   
  Perimeter = a+b+c;
  s = (a+b+c)/2;
  Area = sqrt(s*(s-a)*(s-b)*(s-c));
   
  printf("\n Perimeter of Traiangle = %.2f\n", Perimeter);
  printf("\n Semi Perimeter of Traiangle = %.2f\n",s);
  printf("\n Area of triangle = %.2f\n",Area);

  return 0;
}


Output :-


Please Enter three sides of triangle :
25
25
25

 Perimeter of Traiangle = 75.00

 Semi Perimeter of Traiangle = 37.50

 Area of triangle = 270.63



3. Find the Area of Triangle using Base and Height


/* C Program to find Area Of a Triangle using base and height */

#include<stdio.h>
 
int main()
{
  float base, height, area;
  
  printf("\n Please Enter the Base of a Triangle  :  ");
  scanf("%f", &base);
   
  printf("\n Please Enter the Height of a Triangle  :  ");
  scanf("%f", &height);
 
  area = (base * height) / 2;
   
  printf("\n The Area of a Triangle using Base and Height = %.2f\n", area);
 
  return 0;
}


Output :-



Please Enter the Base of a Triangle  :  25

 Please Enter the Height of a Triangle  :  25
 The Area of a Triangle using Base and Height = 312.50



4. Find the Area of Rectangle



/* C Program to Calculate Area of a Rectangle and Perimeter of a Rectangle */

#include<stdio.h>
int main()
{
  float width, height, Area, Perimeter; 

  printf ("\n Please Enter the Width and Height of the rectangle \n");
  scanf (" %f %f ",&width, &height);

  Area = width * height;
  Perimeter = 2 *(width + height);

  printf("\n Area of a rectangle is: %.2f", Area);
  printf("\n Perimeter of a rectangle is: %.2f", Perimeter);

  return 0;
}


Output :-



Please Enter the Width and Height of the rectangle : 
30
25

 Area of a rectangle is: 750.00
 Perimeter of a rectangle is: 110.00



5. Find the Area of Right Angled Triangle



/* C Program to find Area of a Right Angled Triangle Example */

#include<stdio.h>
#include<math.h>
int main()
{
  float width, height, c, Area, Perimeter; 
  printf("\n Please Enter height and width of the right angled triangle\n");
  scanf("%f%f",&width, &height);

  Area = 0.5 * width * height;
  c = sqrt((width*width) + (height*height));
  Perimeter = width + height + c;
  
  printf("\n Area of right angled triangle is: %.2f\n",Area);
  printf("\n Other side of right angled triangle is: %.2f\n",c);
  printf("\n Perimeter of right angled triangle is: %.2f\n", Perimeter);
  return 0;
}


Output :-



Please Enter height and width of the right angled triangle
25
25

 Area of right angled triangle is: 312.50

 Other side of right angled triangle is: 35.36

 Perimeter of right angled triangle is: 85.36



6. Find Volume and Surface area of Sphere



/* C Program to find Volume and Surface Area of Sphere */

#include <stdio.h>

#define PI 3.14

int main()
{
  float radius, sa,Volume;

  printf("\n Please Enter the radius of a Sphere \n");
  scanf("%f", &radius);

  sa =  4 * PI * radius * radius;
  Volume = (4.0 / 3) * PI * radius * radius * radius;

  printf("\n The Surface area of a Sphere = %.2f", sa);
  printf("\n The Volume of a Sphere = %.2f", Volume);

  return 0;
}


Output :-



Please Enter the radius of a Sphere: 
25
The Surface area of a Sphere = 7850.00
 The Volume of a Sphere = 65416.67



7. Find Volume and Surface area of Cube



/* C Program to find Volume and Surface Area of a Cube */

#include<stdio.h>

int main()
{
  float l, SA,Volume, LSA;

  printf("\n Please Enter Length of any side of a Cube: \n");
  scanf(" %f ", &l);

  SA = 6 * (l * l);
  Volume = l * l * l;
  LSA = 4 * (l * l);

  printf("\n Surface Area of Cube = %.2f", SA);
  printf("\n Volume of cube = %.2f", Volume);
  printf("\n Lateral Surface Area of Cube = %.2f", LSA);

  return 0;
}


Output :-



Please Enter Length of any side of a Cube: 
25

 Surface Area of Cube = 3750.00
 Volume of cube = 15625.00
 Lateral Surface Area of Cube = 2500.00



8. Find the Volume and Surface area of Cylinder



/* C Program to find Volume and Surface Area of a Cylinder */

#include<stdio.h>
#include<math.h> 

int main()
{
  float radius, height;
  // L = Lateral Surface Area of a Cylinder, T = Top Surface Area
  float sa,Volume, L, T;

  printf("\n Please Enter the radius and height of a cylinder \n");
  scanf("%f %f", &radius, &height);

  sa = 2 * M_PI * radius * (radius + height);
  Volume = M_PI * radius * radius * height;
  L = 2 * M_PI * radius * height;
  T = M_PI * radius * radius;

  printf("\n Surface Area of a cylinder = %.2f", sa);
  printf("\n Volume of a Cylinder = %.2f", Volume);
  printf("\n Lateral Surface Area of a cylinder = %.2f", L);
  printf("\n Top OR Bottom Surface Area of a cylinder = %.2f", T);
  
  return 0;
}


Output :-



Please Enter the radius and height of a cylinder: 
25
25

 Surface Area of a cylinder = 7853.98
 Volume of a Cylinder = 49087.39
 Lateral Surface Area of a cylinder = 3926.99
 Top OR Bottom Surface Area of a cylinder = 1963.50



9. Find the Volume and Surface area of Cone



/* C Program to find Volume and Surface Area of a Cone */
#include <stdio.h>
#include <math.h>

int main()
{
  float radius, height;
  float Volume, SA, l, LSA;
  
  printf("\n Please Enter Radius and Height of a Cone :\n");
  scanf("%f %f", &radius, &height);

  l = sqrt(radius * radius + height * height);
  SA = M_PI * radius * (radius + l);
  Volume = (1.0/3) * M_PI * radius * radius * height;
  LSA = M_PI * radius * l;

  printf("\n Length of a Side (Slant)of a Cone = %.2f", l);    
  printf("\n Surface Area of a Cone = %.2f", SA);
  printf("\n Volume of a Cone = %.2f", Volume);
  printf("\n Lateral Surface Area of a Cone = %.2f", LSA);

  return 0;
}


Output :-


Please Enter Radius and Height of a Cone :
25
25
Length of a Side (Slant)of a Cone = 35.36
 Surface Area of a Cone = 4740.30
 Volume of a Cone = 16362.46
 Lateral Surface Area of a Cone = 2776.80
 

Post a Comment

0 Comments