Header Ads

Write a program to calculate perimeter of rectangle. Take sides, a & b, from the user

Formula to calculate perimeter of rectangle
2(l+b)


where l = length, b = width



Code :


# include<stdio.h>

// main function
int main() {

    // declaring variable type
    int a,b;

    // taking input
    printf("Enter Length : ");
    scanf("%d", &a);
    printf("Enter width : ");
    scanf("%d", &b);

    // calculate and print Perimeter
    printf("Perimeter of Rectangle %d", 2*(a+b));
    return 0;
}

How to execute the C Code :

Open the terminal in the path folder and write the commands as follow :

gcc filename.c
./a.exe
(use ./a.out in mac os)

Output :

Enter Length : 10
Enter width : 10
Perimeter of Rectangle 40

Post a Comment

0 Comments