Program to print following series:
Code:
import java.util.*;
import java.io.*;
class Test{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int i=0;i<t;i++){
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
int s,e,z = 0;
for(int j=0;j<n;j++)
{
e=(int)Math.pow(2,j);
s =a +e*b+z;
z=e*b+z;
System.out.print(s+" ");
}
System.out.println();
}
in.close();
}
}
Code:
import java.util.*;
import java.io.*;
class Test{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int i=0;i<t;i++){
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
int s,e,z = 0;
for(int j=0;j<n;j++)
{
e=(int)Math.pow(2,j);
s =a +e*b+z;
z=e*b+z;
System.out.print(s+" ");
}
System.out.println();
}
in.close();
}
}
Ouput: