C++ Tutorial for Beginners 19 - Getting the sum of values in an array

preview_player
Показать описание
To find the sum of an array element in C++ programming
How to add element to C++ array
I need help with finding the sum of elements in an array
c++ program to find sum of array element
c++ program to add two arrays
Sum of One Dimensional Array
Рекомендации по теме
Комментарии
Автор

\\For taking input frm the user for the array sum;#include<iostream>
Using namespace std;
Main(){
Int n, I, sum=0;
Cin>>n;
Int arr[n];
For(I=0;I<n;I++) {
Cin>>arr[i];
}
For(int I=0;I<n;I++) {
Sum+=arr[I]; //array sum;
}
Cout<<"sum of all the elements is"<<sum<<endl;
}
}

ammuluammu
Автор

What if we're taking the values as input from the user and we're taking the amount of values to be put in the array(i.e. int b[amount]) as input from the user as well?

guyexists
Автор

how about subtraction ?? how can i get the difference of the value in an array??

nikkapaulite
Автор

thank you my brother
I learn from you 
a simple code give the same result

{
    int arrQay [6]= {12, 72, 22, 82, 23, 92};
    int sum ;
    int a =arrQay [0] ;
    int b =arrQay [1] ;
    int c =arrQay [2] ;
    int d =arrQay [3] ;
    int e = arrQay [4];
    int f =arrQay [5] ;
    sum  = a+b+c+d+e+f;
    cout << "The Sum =" << sum << endl;
    return 0;
}

thebaazigar
Автор

brother lam not solve this code because sum is 12 but me show how can l solve brother

hassanabokor