Home > Back-end >  C cycle
C cycle

Time:10-06

Everyone a great god, and how to use the do while loop to a sum of the three digits of the number?

CodePudding user response:

To understand the meaning of the two expressions, can write the
10 I %
I/10

CodePudding user response:

Position and in turn

CodePudding user response:

Already know is 3 digits, and with what cycle?
N/100 is the digits of n
(n % 100)/10 is ten digits of n
To single digits of n is n % 10
Had taken each together

CodePudding user response:


 
#include
Int main () {
char s[10];
Int ans=0;
The scanf (" % s ", s);
for(int i=0; i<3; + + I) {
Ans +=(s [I] - '0');
}
Printf (" % d ", ans);
return 0;
}

CodePudding user response:

reference 1st floor CHXCHXKKK response:
understand the meaning of the two expressions, will write the
10 I %
I/10

Thanks for a great god

CodePudding user response:

refer to the second floor gentleman not hatred response:
position and in turn

Thank you

CodePudding user response:

The
reference room no. 3, 4/f, reply:

 
#include
Int main () {
char s[10];
Int ans=0;
The scanf (" % s ", s);
for(int i=0; i<3; + + I) {
Ans +=(s [I] - '0');
}
Printf (" % d ", ans);
return 0;
}

Thanks for a great god
  • Related