Home > Back-end >  Don't know where is wrong, has been an error (? '0 `?)
Don't know where is wrong, has been an error (? '0 `?)

Time:05-11

For a given positive integer N, its digits and the sum of digits,

Input format:
Input in a row in a given no more than 10
? 9
?? The positive integer N,

The output format:
In a line of output N digits and the sum of digits, separated with a space between,

Input the sample:
321
The output sample:
3 6



# include

Int main ()

{int n, I, x=0, y;

The scanf (" % d ", & amp; n);

If (n<=1000000000 & amp; & n!=0)

{the for (I=1; i<=9; I++)

{n=n/10;

Y=n % 10;

X +=y;

If (n==0)

break;

The else

i++;

}

Printf (" % d % d ", I, x); }

return 0;

}

CodePudding user response:

Code function at the end of the day is not others to help you see or interpretation or comment; But by myself calm down and take a long enough time and energy to do it yourself step or set a breakpoint or step to perform to a certain intermediate result shows or written to the log file analysis step by step,
Remind: cow x teacher cannot replace the student understand and use the toilet!
Single step debugging and set breakpoint debugging (VS IDE compilation connection through later, press F10 or F11 key step, press Shift + F11 exit the current function; In a press F9 set breakpoints after press F5 execution stops at the breakpoint,) is one of the programmers must master the skills,

CodePudding user response:

 # include 
#include
Int main (void)
{

If # 1
Char digit [128], * PSTR;
Int CNT=0, sum=0;

The fgets (digit, sizeof (digit), stdin);

If (digit [0]=='-') {
Printf (" Error input! \n");
return -1;
}
PSTR=digit;
While (* PSTR) {
If (isdigit (* PSTR)) {
The sum +=* PSTR - '0'.
cnt++;
}
Pstr++;
}

Printf (" % d % d \ n ", CNT, sum);
# the else
Int n, I, x=0, y;

The scanf (" % d ", & amp; n);

If (n<=1000000000 & amp; & n!=0)
{
for(i=1; i<=9; I++)

{
N=n/10;
Y=n % 10;
X +=y;
If (n==0)
break;
The else
i++;
}
Printf (" % d % d ", I, x);
}
# endif
return 0;

}

For your reference ~

CodePudding user response:

Modified as follows, for your reference:
 # include 

Int main ()

{
Int n, I=0, x=0, y;

The scanf (" % d ", & amp; n);

If (n<=1000000000 & amp; & n!=0)

{
While (n)//for (I=1; i<=9; I++)

{
Y=n % 10;
X +=y;
N=n/10;
i++;//if (n==0)

//break;

//else

//i++;

}
Printf (" % d % d ", I, x);
}

return 0;
}

CodePudding user response:

Thinking decision code:
 
#include

Int main ()
{
Int n, b, s;

For (b=s=0; ~ the scanf (" % 1 d ", & amp; n); B++, s +=n);
Printf (" % d % d \ n ", b, s);

return 0;
}

CodePudding user response:

references 4 floor early play play nuclear response:
thought decision code:
 
#include

Int main ()
{
Int n, b, s;

For (b=s=0; ~ the scanf (" % 1 d ", & amp; n); B++, s +=n);
Printf (" % d % d \ n ", b, s);

return 0;
}

How do you also need to be warned, the output (end loop)

CTRL + d (Linux) or CTRL + z (Windows)

CodePudding user response:

Methods more than
 # include & lt; stdio.h> 
Int main ()
{
Int n, b=0, s=0;
For (; (n=getchar ()) & amp; & n!='\ n'; B++, s +=n - '0')
Printf (" % d % d \ n ", b, s);
return 0;
}

 # include & lt; stdio.h> 
Int main (void)
{
Int a=0, b=0, c;
The scanf (" % d ", & amp; C);
For (; c> 0; + a + b=c % 10, c/=10);
Printf (" % d % d ", a, b);
}

CodePudding user response:

There are, I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related