Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

1+x+x2+x3+…………………………………………+x^n Write a program to show the sum of the series when x & n is input through the keyboard.


Source Code :

#include<stdio.h>
#include<math.h>
void main()
{
      int x,n,i,j;
      float sum=1;
      clrscr();
      printf("\nEnter the Value of 'x' : ");
      scanf("%d",&x);
      printf("\nEnter the Value of 'n' : ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            sum+=pow(x,i);
      }
      printf("\nSum of the Series : %5.2f",sum);
      getch();
}

Output :

Enter the Value of ‘x’ : 2

Enter the Value of ‘n’ : 5

Sum of the Series : 63.00

No comments:

Post a Comment