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.

Respuesta :

Answer:

#include <stdio.h>

#include <string.h>

int main(){

   char number[100];

   printf("Number: ");

   scanf("%s", number);

   int sum = 0;

   for(int i =0;i<strlen(number);i++){

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

   }

           printf("Sum: %d",sum);

   return 0;

}

Explanation:

This declares a c string of 100 characters

   char number[100];

This prompts user for input

   printf("Number: ");

This gets user input

   scanf("%s", number);

This initializes sum to 0

   int sum = 0;

This iterates through the input string

   for(int i =0;i<strlen(number);i++){

This adds individual digits

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

   }

This prints the calculated sum

           printf("Sum: %d",sum);

   return 0;

The program that ask the user to enter a series of single digit number and display the sum of all the single digit number, highest number and lowest number is as follows:

x = input("input the series of number: ")

y = []

for i in x:

  y += i

integer_map = list(map(int, y))

print(sum(integer_map))

print(max(integer_map))

print(min(integer_map))

The code is written in python.

Code explanation:

  • The first line of code ask the user for the series of numbers. The user input is stored in the variable "x"
  • The y variable is an empty array
  • we use the for loop to loop through the users series of number. Then add the looped items to the empty array.
  • Then we map the string of list to an integers
  • Finally, we print the sum , maximum and minimum number of the list.

learn more on python program: https://brainly.com/question/16025032?referrer=searchResults

Ver imagen vintechnology
Ver imagen vintechnology
ACCESS MORE
EDU ACCESS