gpt4 book ai didi

C语言: I want to add all the positive integers when a negative number is inserted

转载 作者:行者123 更新时间:2023-11-30 20:59:23 26 4
gpt4 key购买 nike

我想在输入负数时将所有正整数相加。

Click for Example

int number;
int total;
int loopcount;
int a;
number = 0;
a = 0;
total = 0;

for(loopcount = 0; loopcount >=0; loopcount = loopcount + 1)
{
printf("Enter Integer: ");
scanf("%d", &number);
a = number;

if (a >= 0)
{
total = total + number;
}
else if(a < 0)
{
printf("Total positive int = %d\n", &total);
break;
}
}

最佳答案

问题是这样的:

printf("Total positive int = %d\n", &total);
^

您不是打印total变量的值,而是打印它的地址。删除&。正确的做法是:

printf("Total positive int = %d\n", total);

关于C语言: I want to add all the positive integers when a negative number is inserted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690378/

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