-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsum of array.cpp
72 lines (57 loc) · 1.46 KB
/
sum of array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//sum of arrray using funtion
/* #include <iostream>
using namespace std;
void sumofarray(int arr[],int n){
int sum=0,s=1;
for( int i=0;i<n;i++)
{
sum=sum+arr[i];
}
cout<<"sum of array is"<<sum<<endl;
for(int i=0;i<n;i++)
{
s*=arr[i];
}
cout<<"product of their element is "<<s<<endl;
}
int main() {
int arr[100], i,n;
cout<<"enter the size of array"<<endl;
cin>>n;
cout<<"enter the array elements"<<endl;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sumofarray(arr,n);
}*/
//sumof array taking input
/* #include<iostream>
using namespace std;
int main(){
int arr[10],i=0,n,sum=0;
cout<<"enter the size of the array"<<endl;
cin>>n;
cout<<"enter the array elemrnts"<<endl;
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n;i++)
{
sum=sum+arr[i];
}
cout<<"sum of array element is:"<<sum<<endl;
return 0;
}*/
//sum of array
#include<iostream>
using namespace std;
int main(){
int i, sum=0;
int arr[5]={2,4,6,8,10};
for(int i=0;i<5;i++)
{
sum+=arr[i];
}
cout<<"sum of array element is:"<<sum<<endl;
return 0;
}