如果我有这样的事情:
printf("\nEnter 2 numbers: \n");
scanf(" %d %d", &a, &b);
add (a,b)
int a,b;
{
printf ("%d", a+b);
}
然后想要再次运行该 block ,但使用“无”的新变量,就像输入第一个 printf 语句时一样。有什么建议吗?
最佳答案
首先避免使用K&R
C 语法
/* Your function
add (a,b)
int a,b;
{
printf ("Sum = %d\n", a+b);
}
*/
/* Use following style*/
void add (int a,int b)
{
printf ("Sum = %d\n", a+b);
}
int main()
{
int i,a,b; // Declare variables
int n=5; // Call it say n=5 times
for(i=0;i<n;i++) //Use a for loop to iterate for n times
{
printf("\nEnter 2 numbers: \n");
if(scanf(" %d %d", &a, &b)==2) // with 2 new inputs
add(a,b); //Call your add function
}
}
关于c - C 中的点或 "reset"变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18687262/