Computer Science, asked by kumaresankp21, 9 months ago

write a program to find the sum of the series
S=1+x+x^2+.........+x^n​

Answers

Answered by Suriddhim
3

#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

}

Attachments:
Answered by anuragniitverma
0

Answer:

import java.util.Scanner

class Series

{

public static void main(String[] args)  

{

 int i,n;

 float x,sum=1;

 Scanner sc = new Scanner(System.in);  

 System.out.print("Enter x and n : ");  

 x = sc.nextInt();  

 n = sc.nextInt();  

 for(i=1;i<=n;++i)

 {

   sum+=Math.pow(x,i);

 }

 System.out.println("nSum="+sum);

}

}

Explanation:

Similar questions