Loop Question

Dear All,

Is it possible make below NPV calculation automatically? I mean can we use any loop for the following;

NPV= C0 + (C1/(1+r)) + (C2/(pow(1+r, 2))) + (C3/(pow(1+r, 3))) + (C4/(pow(1+r, 4)));
cout<<NPV<<'\n';

 ``1234567891011121314151617181920212223242526272829`` ``````// NPV calculation #include #include #define r 0.12 //12% opportunity cos of capital using namespace std; int main() { //variables declaration const short C0=-2000; //initial investment unsigned short C1=500; // cash inflow in year 1 unsigned short C2(225); // cash inflow in year 2 unsigned short C3=336; // cash inflow in year 3 unsigned short C4(40); // cash inflow in year 4 float NPV; // NPV=? // Let s put the formula of NPV for 4 years: NPV=Co + C1/(1+r) + C2/(1+r)^2 + C3/(+r)^3 + C4/(1+r)^4 NPV= C0 + (C1/(1+r)) + (C2/(pow(1+r, 2))) + (C3/(pow(1+r, 3))) + (C4/(pow(1+r, 4))); cout<

I would appreciate any help,

 ``1234567891011121314`` ``````const unsigned int N = 5; short C[N]; C[0] = -2000; C[1] = 500; C[2] = 225; C[3] = 336; C[4] = 40; float NPV = 0; for( int i = 0; i < N; i++ ) NPV += C[i] / pow(1+r, i); cout << NPV;``````