Monday, 2 July 2012

Compare Area and Perimeter in C


Code -


//___Program to check whether the area of a rectangle is greater than its perimeter____

/* Area of rectangle = Length of rectangle * Breadth of rectangle

   Perimeter of rectangle = 2 ( Length * Breadth ) */

//_______________Including Header Files__________________

#include<stdio.h>

#include<conio.h>

//__________Header file mainly included for the getch() function__________

int main()
{
int length = 0, breadth = 0, area = 0, perimeter = 0;

//_________Variable declaration and initialization____________

printf("\n\n       _____ Program will compare the Area and Perimeter of Rectangle _____");

printf("\n\n\n  Enter the length of the Rectangle  - ");

//_________Prompting the user to enter the length of the rectangle___________

scanf("%d", &length);

//_________Reading the user input and storing it in varible length of type integer______

printf("\n\n  Enter the breadth of the Rectangle - ");

//_________Prompting the user to enter the breadth of the rectangle__________

scanf("%d", &breadth);

//_________Reading the user input and storing it in variable breadth of type integer____

area = length * breadth;

//_____________Calculating the area of the rectangle_____________________________

perimeter = 2 * ( length + breadth);

//_____________Calculating the perimeter of the rectangle________________________

if (area > perimeter)

//_____________Checking for the area being greater than the perimeter____________

{
printf("\n\n\t Area of rectangle with dimensions Length - %d and Breadth - %d is \n\n\t\t\t Greater than its Perimeter", length, breadth);
}
else if (area == perimeter)

//_____________Checking for the area being equal to the perimeter________________

{
printf("\n\n\t Area of rectangle with dimensions Length - %d and Breadth - %d is \n\n\t\t\t Equal to its Perimeter", length, breadth);
}
else

//____This part will automatically check for the area being smaller than the perimeter____

{
printf("\n\n\t Area of rectangle with dimensions Length - %d and Breadth - %d is \n\n\t\t\t Less than its Perimeter", length, breadth);
}

getch();

return 0;
//_return 0 will tell the compiler that the progrem has executed successfully without any error____

}

Follow Us on Facebook -  Assignment Hub

No comments:

Post a Comment