在执行矩形区域时使用"area=b*h"的问题

  • 本文关键字:area 问题 执行 区域 area
  • 更新时间 :
  • 英文 :


我正在解决一个应该计算矩形面积的问题。

我的代码如下:
#include<stdio.h>
int main()
{
int a,h;
int area;
**area=a*h;**
printf("enter the value of a=  ");
scanf("%d", &a);
printf("the value of a is %d  n", a);
printf("enter the value of h=  ");
scanf("%d", &h);
printf("the value of h is %d n", h);

printf("The area is %d", area);
return 0;
}

我的问题是:当我使用"area=a*h"时(机器阅读)有什么问题?在声明&;int &; area&;?

代码清晰,

#include<stdio.h>
#include<conio.h>

int main() {
int length, breadth, area;

printf("nEnter the Length of Rectangle : ");
scanf("%d", &length);

printf("nEnter the Breadth of Rectangle : ");
scanf("%d", &breadth);

area = length * breadth;
printf("nArea of Rectangle : %d", area);

return (0);
}

你的问题是,你试图在从用户处获得数字之前计算值。实际上你需要在阅读"a"之后使用这个area=a*h;。和";h"从键盘。

最新更新