Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
输入负数时,我想添加所有正整数。

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 - C语言:我要在插入负数时添加所有正整数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47690378/

10-11 21:15