1.

WAP to print the sum of the following series s=0+1+3+7+15+31+..... Upto n terms

Answer»

n:-Write a program to print the SUM of the following SERIES. S=0+1+3+7+15+31+.....N termsProgram:-In Javaimport java.util.*;class Sum{public static void main(STRING args[]){int n, i, s=0, a=0;Scanner sc=new Scanner(System.in);System.out.print("Enter the value of N: ");n=sc.nextInt();for(i=1;i<=n;i++){s=s+a;a=a+i;}System.out.println("Sum of the series is: "+s);}}In Pythonn=int(input("Enter N: "))s=a=0for i in range(1,n+1): s=s+a a=a+iprint("Sum of the series is: ",s)



Discussion

No Comment Found