Skip to content

Commit 689c152

Browse files
Added Sum of Subarray Program
1 parent 3f87076 commit 689c152

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

sumOfSubArray.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main(){
5+
int n;
6+
cin>>n;
7+
8+
int arr[n];
9+
for(int i=0;i<n;i++){
10+
cin>>arr[i];
11+
}
12+
13+
int sumfinal=0;
14+
for(int i=0;i<n;i++){
15+
int sum=0;
16+
for(int j=i;j<n;j++){
17+
sum+=arr[j];
18+
}
19+
sumfinal+=sum;
20+
}
21+
cout<<sumfinal<<endl;
22+
return 0;
23+
}

0 commit comments

Comments
 (0)