#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i;
cout << "Enter A Number :: ";
cin >> n;
int a[n], p[n+1];
p[0] = 0;
cout << "\nEnter Array Element :: ";
for(i=0;i<n;i++)
{
cin >> a[i];
p[i+1] = p[i] + a[i];
}
cout << "\nPrefix Array :: ";
for(i=1;i<=n;i++)
cout << p[i] << " ";
cout << "\n";
return 0;
}
using namespace std;
int main()
{
int n, i;
cout << "Enter A Number :: ";
cin >> n;
int a[n], p[n+1];
p[0] = 0;
cout << "\nEnter Array Element :: ";
for(i=0;i<n;i++)
{
cin >> a[i];
p[i+1] = p[i] + a[i];
}
cout << "\nPrefix Array :: ";
for(i=1;i<=n;i++)
cout << p[i] << " ";
cout << "\n";
return 0;
}
Comments
Post a Comment