do number 2 only and please show that code works through command prompt. #1 ques
ID: 3797961 • Letter: D
Question
do number 2 only and please show that code works through command prompt. #1 question is shown so you can see what number 2 is based off of.
Explanation / Answer
C Code:
#include <stdio.h>
int main()
{
char numStr[10], digit;
int sum = 0, i, l;
printf("Enter a number ");
scanf("%s", numStr);
l = strlen(numStr);
for (i = 0; i<l ; i++) {
digit = numStr[i];
printf("%c ", digit);
sum = sum + (int)digit - (int)'0';
}
printf(" Sum = %d ",+sum);
return 0;
}
Terminal window:
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Enter a number 12459 1 2 4 5 9 Sum = 21
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.