write a program in C plus plus to enter any 10 integers in 1D array and display the total sum of those digits
Answers
#include<iostream>
using namespace std;
int main()
{
int num_array[10], sum=0;
cout<<"Enter the numbers\n";
for(int i=0;i<10;i++)
{
cin>>num_array[i];
sum+=num_array[i];
}
cout<<"Sum of array elements = "<<sum;
return 0;
}
Following are the programs for the above question:
Explanation:
#include <iostream>//This is to include the header file.
using namespace std;
int main()//The definition of the Main function.
{
int array_variable[10],increment=0,Total=0; //The statement of variable declaraction.
while(increment<10) //while loop to take the value and for add the value.
{
cin>>array_variable[increment];//take the value from the user and store it into array variable
Total=Total+array_variable[increment];//It adds the value of array variable.
increment++;//increment operation for the loop.
}
cout<<"The sum is: "<<Total; //print the sum value.
return 0; //return statement.
}
Output:
- If the user gives the input as 0,0,1,2,3,0,0,0,0,0 then the output is 6.
- If the user gives the input as 0,0,1,2,3,0,0,0,0,1 then the output is 7.
Code Explanation :
- The above code is written in the c++ language, which is used to take the 10 value from the user and add the value and prints the value.
- The while loop is used to take the value from the user and add the value of an array.
Learn More:
- Programing : https://brainly.in/question/12809215