Advertisement
Guest User

12321

a guest
Feb 8th, 2016
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.     int n ,  i=0;
  10.     double s = 0, r;
  11.    
  12.     cout <<"Input n:";
  13.     cin >> n;
  14.     while(i < n)
  15.     {
  16.         i++;
  17.         r = 1/(pow(2,n));
  18.         s+=r;
  19.        
  20.     }
  21.     cout <<"Sum=" << s+1;
  22.     getch();
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement