Filling integer array members based on user input and summing them – CSKC
Sign In

Search

Solved Problem #CPP#5370    siteicon   siteicon  

Problem Statement - Filling integer array members based on user input and summing them

Write a program to collect 5 numbers from user into a 1-D integer array. Calculate sum of all the input numbers and print it with a suitable message.

Solution

TC++ #5370

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

int arr[5],sum=0;
Integer array of 5 members declared. Integer sum is initialised with 0.

for(int i=0;i<5;++i)Β {
Loop for collecting array data and also for summing successively

cout<<“Give array member “<<i+1<<” : “;Β cin>>arr[i];

Array member collected in loop for each index position starting from index 0

sum+=arr[i];}
Array member is summed within the loop

cout<<endl<<“Array sum = “<<sum<<endl;
Sum is printed.


Share

Created: 9-Dec-2018 23:34 | Updated: 9-Dec-2018 23:34|