/* */ Click to Join Live Class with Shankar sir Call 9798158723

print the area of given figure in C ?


Q.) print area of rectangle in C by getting length and breadth from the user ?
 #include<stdio.h>
 #include<conio.h>
 int main()
 {
	 int length,breadth,area;
	 printf("Enter the length and breadth of the rectangle :");
	 scanf("%d%d",&length, &breadth);
     area = length * breadth; 
     printf("area of rectangle is :%d",area);
     getch();
 }
Output
Enter the length and breadth of the rectangle :7 8    /* say length = 7 and breadth = 8 */.
area of rectangle :56

Program Explanation


Step 1: include header files (#include<stdio.h> and #include<conio.h>).

Step 2: start with main function with return type.

Step 3: parenthesis to start and end the program { }.

Step 4: declare the variables with data types. i.e, values of 'length' and 'breadth' are of integer type so we declare 'length' and 'breadth' with "int" data type. We also declare 'area' as "int" because it returns an integer value.

Step 5: use output function printf() to print the output on the screen.

Step 6: use input function scanf() to get input from the user.

Step 7: using getch() function to hold the screen.


Q.) print area of circle in C by getting radius from the user ?
 #include<stdio.h>
 #include<conio.h>
 int main()
 {
	 float pi=3.14,radius,area;
	 printf("Enter the radius of circle :");
	 scanf("%f",&radius);
     area = pi * radius * radius; 
     printf("area of circle is :%f",area);
     getch();
 }
Output
Enter the radius of circle :4    /* say radius = 4 */.
area of circle :50.240002