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; }