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

Write a program that asks the user to enter a series of single digit numbers wit

ID: 3547852 • Letter: W

Question

Write a program that asks the user to enter a series of single digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

our question here

Explanation / Answer

#include<stdio.h>

#include<string.h>

int main()

{

int i,l,sum=0;

char arr[1000];

scanf("%s",&arr);

l=strlen(arr);

for(i=0;i<l;i++)

{

sum=sum+arr[i]-'0';

}

printf("%d ",sum);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote