错误演示
#include <stdio.h>
int main()
{
float pai = 3.141592;
int r, zc, mj;
zc = 2 * pai * r; //没有给zc mj r 赋初始值,故不能直接放在前面
mj = pai * r * r; //定义的zc和mj要在scanf抓取地址给其r zc mj 赋值之后再进行运算 应该放到scanf后面
printf("输入半径\n: ");
scanf("%d", &r);
printf("以%d为半径的圆面积和周长分别是%d和%d", r, mj, zc);
}
正确代码
#include <stdio.h>
int main()
{
float pai = 3.141592;
int r, zc, mj;
printf("输入半径\n: ");
scanf("%d", &r);
zc = 2 * pai * r; //此位置
mj = pai * r * r; //此位置
printf("以%d为半径的圆面积和周长分别是%d和%d", r, mj, zc);
}