Hello, I'm trying to make a C++ program which calculates the following series:
1/3^1 + 1/3^2 + .... + 1/3^n
So far I've tried this
but it always returns zero. Any help would be appreciated.
1/3^1 + 1/3^2 + .... + 1/3^n
So far I've tried this
Code:
#include<iostream> using namespace std; void main() { int z=1, n, n2; float num=1/3, sum=0; cout<<"n= "; cin>>n; while(n > 0) { z=1; n2 = n; while(n2 > 0) { z = num * z; n2--; } sum = z + sum; n--; } cout<<endl<<sum; }
Comment