C program to calculate and print area and perimeter of the rectangle

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 SquareArea and Perimeter of Circle : Next >>>

All Programs      C Simple Programs      If Condition Programs      Switch Statement Programs      Loop Programs       Conversion Programs      Pattern Programs       Single Dimension Numeric Array programs       Double Dimension Numeric Array programs      Single Dimension Character Array programs

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