Ask Question

Problem statement: Create and design an application that lets the user enter a string containing a series of numbers separated by commas. This is an example of valid input: 7, 9, 10, 2, 18, 6 The program should calculate and display the sum of all the numbers entered as input.

+3
Answers (1)
  1. 8 September, 01:10
    0
    Following are the program which is given below:

    #include / /defining header file

    using namespace std;

    int main () / /defining main method

    {

    int a[10], i=0, sum=0, n2; / /defining integer variables

    cout<<"Enter total element you want to insert: "; / /print message

    cin>>n2; / /input values

    for (i=0; i
    {

    cin>>a[i]; / /input values

    }

    cout<<"array elements: "; / /print message

    for (i=0; i
    {

    cout<
    }

    for (i=0; i
    {

    sum=sum+a[i]; //add all values

    }

    cout<
    return 0;

    }

    Output:

    Enter total element you want to insert: 6

    7

    9

    10

    2

    18

    6

    array elements: 7,9,10,2,18,6,

    sum: 52

    Explanation:

    The description of the program code as follows:

    In the above program integer variables "i, n, and sum" and a single dimension array "a[]" is declared. In the next step variable "n" is used, that input a value from the user end. Then three for loop is declared, in the first, for loop it will input values from the user-end, in the second loop it will print all the value of the array and separated by commas. In the last loop, it will calculate the sum of the given number and print its final value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Problem statement: Create and design an application that lets the user enter a string containing a series of numbers separated by commas. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers