Computer Science, asked by hhhhyyrfft, 10 months ago

Write a program to find the sum of the following series:
s= 1/2 + 1/4 + 1/8 + 1/16.............. to n terms

Answers

Answered by Anonymous
21

import java.util.*;

public class Series

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

double a,n,s=0;

System.out.println("Enter the value of n");

n = in.nextDouble();

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

s=s+1.0/Math.pow(2,a);

System.out.println("The sum is" +s);

}

}

Answered by Anonymous
12

#include<stdio.h>

int main()

{

int i,N;

float sum;

/*read value of N*/

printf("Enter the value of N: ");

scanf("%d",&N);

/*set sum by 0*/

sum=0.0f;

/*calculate sum of the series*/

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

sum = sum + ((float)1/(float)i);

/*print the sum*/

printf("Sum of the series is: %f\n",sum);

return 0;

}

#lovelove!

Similar questions