Statement of C Program: This Program prints the sum of the following Series:
scanf("%d" , &n);
#include<stdio.h>
#include<conio.h>
void main()
{
int n , sign , term_cont;
float term , num , den , sum;
clrscr();
sum=0;
printf(" Enter the number of terms in the series\n");
sign = 1;
num = 1;
den = 1;
term_cont = 1;
do
{
term = (num/den) * sign;
sum + = term;
den ++;
sign* = (-1); /* sign = sign * (-1) */
term_cont ++;
} while (term_cont<=n);
printf(" Sum of the series = %f\n" , sum);
} /* End of main() */
Output:
Enter the number of terms in the series
4
Sum of the series = 0.58
That's All
0 Response to "WAP to Calculate the sum of given Series by using do-while loop or Statement"
Post a Comment