Write a program to find the sum of the series:
s=1-a+a^2-a^3+a^4-a^5......................+a^10
Answers
Answered by
8
import java.util.*;
public class Series
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
double i,a,s=0;
System.out.println("Enter the value of a");
a= in.nextDouble();
for(i=0;i<=10;i++)
{
if(i%2==0)
s=s+ Math.pow(a,i);
else
s= s-Math.pow(a,i);
}
System.out.println("The sum of the series =" +s);
}
}
Answered by
17
#include<stdio.h>
int main() {
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series: ");
scanf("%d",&n);
sum = (n * (n + 1)) / 2;
printf("Sum of the series: ");
#( ˘ ³˘)♥
Similar questions