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.
#include #include int main() { clrscr(); int arr[5],sum=0; for(int i=0;i<5;++i) { cout<<"Give array member "<>arr[i]; sum+=arr[i]; } cout< #include using namespace std; int main() { int arr[5],sum=0; for(int i=0;i<5;++i) { cout<<"Give array member "<>arr[i]; sum+=arr[i]; } cout< #include using namespace std; int main() { int arr[5],sum=0; for(int i=0;i<5;++i) { cout<<"Give array member "<>arr[i]; sum+=arr[i]; } cout< Test it !Test CPP Code !XThe code has been copied automatically for you in the clipboard. After that open any of the service and press cntrl-v to paste in the given code area. Needs a bit of tweaking as per the link. repl.it CPP cpp.sh CPP Ideone CPP Browxy CPP Show Run Output Give array member 1 : 10 Give array member 2 : 20 Give array member 3 : 30 Give array member 4 : 40 Give array member 5 : 50 Array sum = 150 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. CSKC| Created: 9-Dec-2018 | Updated: 9-Dec-2018| Post Views: 633
Give array member 1 : 10 Give array member 2 : 20 Give array member 3 : 30 Give array member 4 : 40 Give array member 5 : 50 Array sum = 150
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.
CSKC| Created: 9-Dec-2018 | Updated: 9-Dec-2018|
Arrays Concepts and 1-D Arrays