Calculate Area of rectangle in C language | C Tutorial - ramCoder

 Hello Coders, in this article we will learn how to create an C program to calculate the area of rectangle. I have already created an youtube video for this topic. If you want, you can even watch that tutorial in YouTube. In order to code this program, we will first need to add the headers file in the program.

#include <stdio.h>
#include <conio.h>{codeBox}

After finishing up with this, we will then declare the function i.e. void main() and start coding the logic. We first of all declared three variables, one for length, one for breadth and one for the area of rectangle. Then we asked for the input to the user with the scanf function in C. After we asked for both the input, then we wrote the formula for the area of rectangle and then printed the output with printf function in C.

The whole program follows top-down approach. The full source code for this logic is given as below:

#include <stdio.h>
#include <conio.h>
void main()
{
    int l, b, a;
    printf("Input length ");
    scanf("%d", &l);
    printf("Input Breadth ");
    scanf("%d", &b);
    a = l * b;
    printf("Area of rectangle is %d", a);
    getch();
}{codeBox} 


 

Post a Comment

Previous Post Next Post