Sum of n numbers

后端 未结 4 785
猫巷女王i
猫巷女王i 2021-01-25 01:32
#include 

int main()
{   
    int m,i,sum,num;

    i=0;
    sum=0;
    scanf(\"%d \",&m);
    while(i

        
4条回答
  •  长情又很酷
    2021-01-25 02:16

    It's causes of extra space in scanf(). Change scanf("%d ",&num) to scanf("%d",&num)

    From Scanf(), fscanf(), You can follow this.

    The scanf() family of functions reads data from the console or from a FILE stream, parses it, and stores the results away in variables you provide in the argument list.

    The format string is very similar to that in printf() in that you can tell it to read a "%d", for instance for an int. But it also has additional capabilities, most notably that it can eat up other characters in the input that you specify in the format string.

    You should write:

    int main()
    {
        int m,i,sum,num;
    
        i=0;
        sum=0;
        scanf("%d",&m);
        while(i

提交回复
热议问题