+ 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; }

24th Feb 2022, 8:32 AM
Abhay mishra
Abhay mishra - avatar
3 Antworten
+ 3
Looks like you are trying to do a calculation without having assigned numbers to it? Lines: area = ... peri = ...
24th Feb 2022, 8:42 AM
Lisa
Lisa - avatar
+ 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?
24th Feb 2022, 8:41 AM
Mustafa A
Mustafa A - avatar
0
Yeah. The code looks incomplete. All of them will end up having 0 as value, then your "area > peri" check will fail.
24th Feb 2022, 8:45 AM
Mustafa A
Mustafa A - avatar