初学C语言的小问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 03:37:59
#include<stdio.h>
main()
{
int x;
printf("enter a number between1-100:",x);
scanf("&d",&x);
printf("\nyou enter the number is %d\n",x);
return 0;
}

不管输入什么数字,电脑显示you enter the number is 3129

麻烦指教

#include<stdio.h>
main()
{
int x;
printf("enter a number between1-100:",x);
scanf("%d",&x);
printf("\nyou enter the number is %d\n",x);
return 0;
}
=================
scanf("%d",&x);

应该为:
#include<stdio.h>
{
int x;
printf("enter a number between 1-100");
scanf("%d",&x);
printf("\nyou number is %d\n",x);
}

return语句是用在调用有返回值的函数上的,以获取返回值,这里没调用当然不必用,还可能造成意想不到的错误

scanf("&d",&x);

是%d

楼上的对c中的main可能有所不了解!
main的默认返回类型是int,所以最帅的刺猬写的没错!
错的地方一楼和二楼都答出来了!