C program to find sum of series 1+x+x^2+……+x^n

C program to find sum of series 1+x+x^2+......+x^n

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
 int i,n;
float x,sum=0;
clrscr(); //to clear the screen
printf(“1+x+x^2+……+x^n”);
printf(“nnEnter the value of x and n:”);
scanf(“%f%d”,&x,&n);

for(i=1;i<=n;++i)
sum+=pow(x,i);
 sum++;
printf(“nSum=%f”,sum);
getch(); //to stop the screen
}

15 thoughts on “C program to find sum of series 1+x+x^2+……+x^n”

    1. #include
      #include
      void main()
      {
      int i,n,x,sum=0;
      printf(“x+x^2+……+x^n”);
      printf(“\n Enter the of x and n:\n”);
      scanf(“%d%d”,&x,&n);

      for(i=1; i<=n;i++)
      {
      sum=sum+x*i;

      }
      printf("\n Sum=%d",sum);

      getch();
      }

  1. Why did you used x as an float?
    since i used it as int and my result changed ony for x=5 and n=2 as 30 instead of 31!

  2. 1. Write an algorithm, draw a flow chart and write a program write a program in ‘C’ to design the following output

    a b c d e d c b a
    a b c d d c b a
    a b c c b a
    a b b a
    a a

    2. Write an algorithm, draw a flow chart and write a program in ‘C’ to find sum of series 1 + 1/x + 1/x2 + 1/x3 + 1/x4 + …….. + 1/xn

    3. Write an algorithm, draw a flow chart and write a program in ‘C’ to find sum of the series of entered number (Exponential Series).
    sum = 1 + x + x2/2! + x3/3! + x4/4! +………….N.

    4. Write an algorithm, draw a flow chart and write a program in ‘C’ to Compute the following series (SINE SERIES).
    sum = x – x3/3! + x5/5! – x7/7! + ……………N

    5. Write an algorithm, draw a flow chart and Write a program in C to generate Electricity Bill

    unit consumed Rate/Unit
    0 – 30 Rs 0.75 /unit
    31 – 100 Rs 2.40 /unit excess of 200 units
    101 – 200 Rs 3.00 /unit excess of 400 units
    above 201 Rs 4.60 /unit excess of 600.

    6. Write an algorithm, draw a flow chart and Write a program in ‘C’ to calculate number of vowels, consonants, spaces, words in a given string.

    7. Write an algorithm, draw a flow chart and Write a program in ‘C’ to check entered string is palindrome or not.

    8. Write an algorithm, draw a flow chart and Write a program in ‘C’ to search a string from the given list of string.

    9. Write an algorithm, draw a flow chart and write a program to find factorial of given number using recursion.

    10. Write an algorithm, draw a flow chart and write a program to minimum or maximum number in an array.

Leave a Comment

Your email address will not be published. Required fields are marked *