Write a program to find the perimeter of a rectangle


Default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Write a program to find the perimeter of rectangle
// Ex: length: 3, breadth: 5 ->Area:16

 
#include<stdio.h>
int main(){
    double l,b;
    printf("Enter the length of Rectangle:");
    scanf("%lf",&l);
    while(l<=0){
        printf("Length can't be negative or zero\n");
        printf("Enter the length of Rectangle:");
        scanf("%lf",&l);        
    }
    printf("Enter the breadth of Rectangle:");
    scanf("%lf",&b);
    while(b<=0){
        printf("Breadth can't be negative or zero\n");
        printf("Enter the breadth of Rectangle:");
        scanf("%lf",&b);        
    }
    
    // calculating perimeter of rectangle
    double perimeter = 2*(l+b);
    printf("\nPerimeter of rectangle: %lf",perimeter);
    getch();
}

No comments:

Post a Comment