Write a program that displays the sum of the following series using do-while loop.
1+ 1/4 + 1/8 + ........ + 1/100
Solution :
#include <iostream.h>
#include <conio.h>
#include<iomanip.h>
int main ()
{
clrscr();
float c , r;
c = 4.0 ;
r = 1.0 ;
do
{
r = r + 1.0 ;
c = c + 4 ;
}while ( c <= 100 );
cout << "Result : " << r ;
return 0;
}
float c , r;
c = 4.0 ;
r = 1.0 ;
do
{
r = r + 1.0 ;
c = c + 4 ;
}while ( c <= 100 );
cout << "Result : " << r ;
return 0;
}
Output:
This program is wrong
ReplyDelete