Five simple C language programs for beginners to find area

When you want to learn programming languages.The very first programming language you need to learn is C language.C language is not object oriented but its has a lot of features.C language is very simple.Every beginner should start from C language.Here are some basic program that will help you to understand structure and semantics of C language.
   
1). C program to find the area of circle.

#include<conio.h>
#define PI 3.14
main()
{float r,area;
printf("Enter radius of circle\n");
scanf("%f",&r);
area=PI*r*r;
printf("Area of circle is %f",area);
getch();}



Working of program:
In this simple program two variables are used.One is used to store radius that will be provided as input by user.Second variable will store result of the formula.At end result will be displayed to user using print statement. 


2). C program to find the area of any triangle.
#include<stdio.h>
 #include<conio.h>
#include<math.h>
 main()
 { float a,b,c;
  float s,area;
    printf("Enter size of each sides of triangle\n");
    scanf("%f%f%f",&a,&b,&c);
    s = (a+b+c)/2;
    area = sqrt(s*(s-a)*(s-b)*(s-c));
    printf("Area of triangle is: %f",area);
    getch();}



Working of program:
In this program five variables are used.a b and c three variables will store the length of each size respectively.Area variable is used to store the result generated by formula. And then generated result will be displayed to the user.

3). C program to find the area of equilateral triangle.

#include<stdio.h>
#include<math.h>
#include<conio.h>
 main() 
 {int side;
   float area;
   area= sqrt(3) / 4;
   printf("\nEnter the Length of Side : ");
   scanf("%d",&side);
   area = area*side*side;
   printf("Area of Equilateral Triangle %f",area);
   getch();}



Working of program:
This program is very tricky.It just takes one side of triangle and provides area of triangle.Did you notice why? Because this program is used to find are of that triangle which have all equal sides.
4). C program to find the area of right angled triangle.

#include<stdio.h>
#include<conio.h>
main()
{float b,h,area;
printf("Enter base and hieght respectively");
scanf("%f%f",&b,&h);
area=0.5*b*h;
printf("Area of triangle is %f",area);
getch();
}





Working of program:
This program will calculate the area of that triangle that contains at least one angle with 90 degrees.User need to enter base and height of triangle and by using formula result will be stored in area variable.Finally area of right angled triangle will be displayed to the user.

5). C program to find the area of rectangle.
#include<stdio.h>
#include<conio.h>
main()
{   int a,b;
 float height,area;
 printf("Enter Two sides 'a' and 'b'\n");
 scanf("%d%d",&a,&b);
 printf("Enter height\n");
 scanf("%f",&height);
 area=.5*(a+b)*height;
 printf("Area of rectangle is %3.2f",area);
 getch();



Working of program:
This program calculates are of a rectangle.We just need to enter two sides of rectangle and height of rectangle.And in no time area of rectangle will be calculated and stored in area variable.

Reactions

Post a Comment

0 Comments