Assignments » Flow Of Control » Set 2 » Solution 14

Source Code: 


#include<iostream>
using namespace std;

int main()
{
 int i,n,sign=-1;
 float sum=0;
 cout<<"Enter the value of n ";
 cin>>n;

 for(i=1;i<=n;i++)
 {
  sign *= -1;
  sum += sign*1.0/i;
 }
 cout<<"log 2 : "<<sum;

 
 return 0;
}



Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top