Problem In Hand
C Program to calculate and print area and perimeter of rectangle
Process and Solution Of Problem
Take input for length and width of rectangle and store in variables
calculate and store area of rectangle in variable.
calculate and store perimeter of rectangle in another variable.
further display area and perimeter
Program/Source Code
#include <stdio.h> int main() { int l,b,a,p; printf("Enter length and width of rectangle "); scanf("%d %d",&l,&b); a=l*b; p=2*(l+b); printf("Area = %d perimeter = %d",a,p); return 0; }
Program Explanation
On execution of the program
* user enteres the length and width of rectangle and store them in a variables “l” and “b”
* Calculation is performed and area is stored in a variable “a” i.e. a=l*b;
* Calculation is performed and perimeter is stored in variable “p” i.e. p=2*(l+b);
* then the result area and perimeter is displayed on the screen
Output:
ex:1 Enter length and width of rectangle 2 3 Area = 6 perimeter = 10 ex:2 Enter length and width of rectangle 3 4 Area = 12 perimeter = 14
You May Also Like:
C Program to find largest of 3 numbers
C Program to print table of a number
C program to check number is +ve, -ve or zero
C program to check number is prime number or not
C program to convert total inches to feet and inches.
<<< Previous: Area and Perimeter of Square | Area and Perimeter of Circle : Next >>> |
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions |