gpt4 book ai didi

c - C 中的点或 "reset"变量

转载 作者:行者123 更新时间:2023-11-30 20:56:54 25 4
gpt4 key购买 nike

如果我有这样的事情:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com