-->

program to get sum of given series with ..................nth terms.

//program to get sum of 12x1+23x3+34x5+..............................nth terms.
#include<stdio.h>
#include<conio.h>
void main()
{
   float i,n,k=2,m=1sum=0;
   printf("enter  positive number for 'n'\n");
  scanf("%f",&n);
  for(i=1;i<=n;i++)
    {               
          sum=sum+(pow(i,k)*m);
           k=k+1;
           m=m+2;
     }
  printf("the sum=%f",sum);
getch();
}
-------------------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get sum, say 'n'.
->let a variable 'sum' with initial value '0'
->we get sum using formula sum=sum+(pow(i,k)*m) because in terms 12x1+23x3+34x5+..     ,
        the first value is i(1),second is k(2) and third is m(1).the values in second and all other terms are changing 
   i----by 1
   k by 1
  m by 2     
  so
        we put these values  inside loop.
->at last we display final sum.

No comments:

Post a Comment