我有两个代码问题,第一个问题是程序要我输入两次号码,第二个问题是程序结束后立即关闭程序。 我试图用getchar()
声明来阻止它,但它似乎并不奏效。函数问题
#include <stdio.h>
int square(int); /*function prototype*/
main()
{
int x; /*defining the function*/
printf("Enter your number\n");
scanf_s("%d \n", &x); /*reading the users input*/
printf("Your new answer is %d \n", square(x)); /*calling the function*/
getchar();
getchar();
}
int square(y) /*actual function*/
{
return y * y;
}
如果你使用'conio.h'库,它效果更好,你不需要担心这个:) – bahjat