请各位高人帮我看一下C语言的代码
- 提问者网友:我没有何以琛的痴心不悔
- 2021-05-15 12:27
void main(void)
{
int a=1,b=2,c=3;
int a2=1234,b2=2345,c2=3456;
int a3=9876,b3=2345,c3=1;
int y =(a+b+c) /3;
int y2=(a2+b2+c2) /3;
int y3=(a3+b3+c3) /3;
printf("\n the average is %d",y);
printf("\n the average is %d",y2);
printf("\n the average is %d",y3);
getchar();
}
我用LCC-Win32做的,却出现错误:Commands defined twince for target 纹?near line 20
- 五星知识达人网友:迷人又混蛋
- 2021-05-15 12:34
没有错,
可能是你的软件的问题
信息来源:初学者之路视频网
- 1楼网友:撞了怀
- 2021-05-15 19:08
我帮你改了下,你复制下:
#include <stdio.h>
void main(void)
{
int a=1,b=2,c=3,y,y2,y3;
int a2=1234,b2=2345,c2=3456;
int a3=9876,b3=2345,c3=1;
y =(a+b+c) /3;
y2=(a2+b2+c2) /3;
y3=(a3+b3+c3) /3;
printf("\n the average is %d",y);
printf("\n the average is %d",y2);
printf("\n the average is %d",y3);
getchar();
}
- 2楼网友:人類模型
- 2021-05-15 18:10
#include <stdio.h>
void main() { int a=1,b=2,c=3; int a2=1234,b2=2345,c2=3456; int a3=9876,b3=2345,c3=1; int y =(a+b+c) /3; int y2=(a2+b2+c2) /3; int y3=(a3+b3+c3) /3; printf("\n the average is %d",y); printf("\n the average is %d",y2); printf("\n the average is %d",y3); getchar(); }
或者
#include <stdio.h>
in main(void) { int a=1,b=2,c=3; int a2=1234,b2=2345,c2=3456; int a3=9876,b3=2345,c3=1; int y =(a+b+c) /3; int y2=(a2+b2+c2) /3; int y3=(a3+b3+c3) /3; printf("\n the average is %d",y); printf("\n the average is %d",y2); printf("\n the average is %d",y3);
return 0; getchar(); }
常见的书写规范
- 3楼网友:人類模型
- 2021-05-15 16:54
- 4楼网友:像个废品
- 2021-05-15 15:29
先定义y y2 y3 再进行运算。
这样看似正确的,但是运行起来会出错误。
符号优先级记得清楚很好,也要养成使用括号的习惯。
#include <stdio.h>
void main(void)
{
int y,y2,y3;
int a=1,b=2,c=3;
int a2=1234,b2=2345,c2=3456;
int a3=9876,b3=2345,c3=1;
y =((a+b+c) /3);
y2=((a2+b2+c2) /3);
y3=((a3+b3+c3) /3);
printf("\n the average is %d",y);
printf("\n the average is %d",y2);
printf("\n the average is %d",y3);
getchar();
}
- 5楼网友:空山清雨
- 2021-05-15 14:05