Draw a flowchart to enter twenty integer data in a single dimensional array and to
Calculate the total sum of the array. Print the array and the sum in the output.
Answers
Answered by
0
Algorithm:
1) Start
2) Declare an array of size 20, A[20]
3) Take input in the array from the user.
for(int i = 0 ; i < 20 ; i++)
cin>>(A[i])
4) Declare a variable sum = 0
5) Start a loop to find sum
for(int i = 0 ; i < 20 ; i++)
sum = sum + A[i]
6) Print all the elements
for(int i = 0 ; i < 20 ; i++)
cout<<A[i]
7) Print sum
cout<<sum
8) End
Program in C++
#include<iostream>
using namespace std;
int main()
{
int A[20] , sum = 0;
cout<<"Enter elements : "<<endl;
for(int i = 0 ; i < 20 ; i++)
{
cin>>A[i];
}
for(int i = 0 ; i < 20 ; i++)
{
sum = sum + A[i];
}
cout<<"Elements are : "<<endl;
for(int i = 0 ; i < 20 ; i++)
{
cout<<A[i]<<" "<<endl;
}
cout<<"Sum = "<<sum;
return 0;
}
Attachments:
Similar questions