麻烦帮我找一下错误 实现 以下程序
#include <stdio.h>void main()
{
int a,b;
float c,d;
int e,f;
unsigned int u,v;
char c1,c2;
scanf("%d %d/n",a,b);
scanf("%f %f/n",c,d);
scanf("%d %d/n",e,f);
scanf("%o %o/n",u,v);
scanf("%c %c/n",c1,c2);
printf("\n");
printf("a=%7d,b=%7d\n",&a,&b);
printf("c=%10.2f,d=%10.2f\n",&c,&d);
printf("e=%17d,f=%17d\n",&e,&f);
printf("u=%o,v=%o\n",&u,&v);
printf("c1=%c,c2=%c\n",&c1,&c2);
}
123 456
17.6 1837.65
2147483640 21474836470
62000 58765
a b 本帖最后由 qiuyouzhi 于 2020-3-16 12:33 编辑
改好了:
#include <stdio.h>
int main()
{
int a,b;
float c,d;
int e,f;
unsigned int u,v;
char c1,c2;
scanf("%d%d/n",&a,&b);
scanf("%f%f/n",&c,&d);
scanf("%d%d/n",&e,&f);
scanf("%o%o/n",&u,&v);
scanf("%c%c/n",&c1,&c2);
printf("\n");
printf("a=%7d,b=%7d\n",a,b);
printf("c=%10.2f,d=%10.2f\n",c,d);
printf("e=%17d,f=%17d\n",e,f);
printf("u=%o,v=%o\n",u,v);
printf("c1=%c,c2=%c\n",c1,c2);
return 0;
}
你这scanf和printf的用法完全混了,建议回炉重造 啊已经解决了呀,还是附上我的,嘿嘿!
int main(){
int a,b;
float c,d;
int e,f;
unsigned int u,v;
char c1,c2;
printf("可以开始输入啦:\n");
scanf("%d %d",&a,&b);//scanf()除了转移字符其他多余字符无意义,固可以去掉’/n‘,scanf()才需要取址符‘&’,printf()不需要‘&’。
scanf("%f %f",&c,&d);
scanf("%d %d",&e,&f);
scanf("%d %d",&u,&v);//如果原意是想随意输入一个数字(10进制)用8进制输入,那此处'%o'改为'%d',否则只能输入8进制数,这样无意义。
getchar();//下一句读取字符时会读取到缓存里遗留的回车,固需清空(小甲鱼老师貌似这样讲的)。
scanf("%c %c",&c1,&c2);
printf("\n");
printf("a=%7d,b=%7d\n",a,b);
printf("c=%10.2f,d=%10.2f\n",c,d);
printf("e=%17d,f=%17d\n",e,f);
printf("u=%o,v=%o\n",u,v);
printf("c1=%c,c2=%c\n",c1,c2);
return 0;
}
测试结果:
可以开始输入啦:
123 456
1.23 4.56
123 456
123 456
a b
a= 123,b= 456
c= 1.23,d= 4.56
e= 123,f= 456
u=173,v=710
c1=a,c2=b
Program ended with exit code: 0
页:
[1]