C Programming
We will be discussing about the program to find area, perimeter and circumstances of simple 2D shapes like square, rectangle, triangle and circle.
C program to find area and circumstances of a circle.
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float pi=3.14,area,ci;
clrscr();
printf("Enter radius of the circle:");
scanf("%d",&r);
area=pi*r*r;
printf("Area of circle=%f\n", area);
ci=2*pi*r;
printf("Circumference = %f\n, ci);
getch();
}
Output:
Enter radius of the circle: 2
Area of circle= 2.0000
Circumferences=12.5600
Explaination:
- Header file stdio.h - standard input and output to get input and show output, conio.h - console input and output.
- void main - function returning value will be null.
- int , float - declare the type of variable.
- clrscr - clear the screen.
- printf - used to print in output screen.
- scanf - used to accept input, and read.
- getch - used to hold the screen until the user gives any type of input.
- Formula for area of circle is pi*r*r and circumference of circle is 2*pi*r.
The above program gives the area and circumferences of circle. We can find the area and perimeter of square, rectangle, and triangle by simple changes like, change the formula, Depending on formula we have to chose variable and declare. so we get output as per our requirement.
Area of square=a*a.
Area of rectangle=l *w. (Hint:we have to give two input here, in above program we considered one variable to give one input.)
Area of triangle = 1/2(b*h).
perimeter of square= 4*a.
perimeter of rectangle=2*(a+b).
perimeter of triangle= a +b+sqr(a+b).
I have mentioned you some formulae guys,try it out on your own. If you find errors or doubt mention in the comment below.
In following days we will discuss more programs in detail. If you like to learn more just follow me regularly. If you have any question to ask mention below in comment.Thank you......
Comments
Post a Comment