+ 1
Anyone please tell me why it's output giving wrong answer .
// Write a program to calculate area and perimeter of rectangle , then calculate which one is greater . #include<stdio.h> int main() { int l, w, area , peri; area = l * w ; peri = 2 * (l + w) ; printf("Width of Rectangle = \n"); scanf("%d", &l); printf("length of Rectangle =\n"); scanf("%d", &w); printf("area of rectangle is %d\n", area); printf("perimeter of rectangle is %d\n", peri); if (area > peri) { printf("Area is grater than perimeter") ; } else { printf("perimeter is greater than area") ; } return 0; }
3 Answers
+ 3
Looks like you are trying to do a calculation without having assigned numbers to it?
Lines:
area = ...
peri = ...
+ 1
How do you assign value to your parameters? Also, what's the answer that you get? Is the answer you get consistent or does it change?
0
Yeah. The code looks incomplete. All of them will end up having 0 as value, then your "area > peri" check will fail.