Blogger templates

Pages

Wednesday, 20 June 2012

WAP to Calculate the sum of given Series by using do-while loop or Statement

Statement of C Program: This Program prints the sum of the following Series:

Mathematical Series

#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");

scanf("%d" , &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 comments:

Post a Comment