Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# Design a program that asks the user to enter a string containing a series of

ID: 3743590 • Letter: C

Question

C# Design a program that asks the user to enter a string containing a series of single digit numbers with nothing separating them. The program should display the sum of all the single digit numbers in the string. For example, if the user enters 2514, the method should return 12, which is the sum of 2, 5, 1, and 4. C# please. C# Design a program that asks the user to enter a string containing a series of single digit numbers with nothing separating them. The program should display the sum of all the single digit numbers in the string. For example, if the user enters 2514, the method should return 12, which is the sum of 2, 5, 1, and 4. C# please.

Explanation / Answer

#include <stdio.h>
#include <string.h>
void main()
{
char string[80];
int count, sum = 0;

printf("Enter the string containing digits ");
scanf("%s", string);
for (count = 0; count<strlen(string); count++)
{
if ((string[count] >= '0') && (string[count] <= '9'))
{
sum += (string[count] - '0');
}
}
printf("Sum of all digits = %d ", sum);
}