Home > Back-end >  Pray god to help novice, how do you make this problem?
Pray god to help novice, how do you make this problem?

Time:06-08

CodePudding user response:

Extract the number in the string, and then accumulate?

CodePudding user response:

 # include & lt; stdio.h> 
#include
# define MAX 9999
Int main () {
int sum=0;
Char STR (MAX);
The scanf (" % s ", & amp; STR);
for(int i=0; I & lt; The strlen (STR); + + I) {
The sum +=(STR [I] - '0');
}
Printf (" % d ", sum);
return 0;
}

CodePudding user response:

reference 1/f, one wipe dust response:
extract the number in the string, and then accumulate?

Should be right, so I understand, but the

CodePudding user response:

reference qq_45817801 reply: 3/f
Quote: refer to 1st floor one wipe the dust response:
extract the number in the string, and then accumulate?

Should be right, so I understand, but the

There should be a example online, you look for,

CodePudding user response:

refer to the second floor qq_45798109 response:
 # include & lt; stdio.h> 
#include
# define MAX 9999
Int main () {
int sum=0;
Char STR (MAX);
The scanf (" % s ", & amp; STR);
for(int i=0; I & lt; The strlen (STR); + + I) {
The sum +=(STR [I] - '0');
}
Printf (" % d ", sum);
return 0;
}

Why want to - '0',,,,

CodePudding user response:

You input is character, operation time, you have to put it into a integer

CodePudding user response:

refer to 6th floor qq_45798109 response:
enter the characters you type, operation time, you want to put it into integer

Thank you, thank you for help??????

CodePudding user response:


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