A sequence 1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187.... above is of two series one is made of odd nos. and other is of even nos. we have to find the nth number in series given n is input,output is nth number in series
Answers
Answer:
nth term of the sequence = 2ⁿ⁻¹ , 3ⁿ⁻¹
Explanation:
1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187....
Here two sequences are given:
Sequence 1 : - 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , ........
nth term of the Sequence 1 is - = a*rⁿ⁻¹ = 1*(2)ⁿ⁻¹ = 2ⁿ⁻¹
Sequence 2: -
1 , 3 , 9 , 27 , 81 , 243 , 729 , 2187 , .........
= a*rⁿ⁻¹ = 1*3ⁿ⁻¹ = 3ⁿ⁻¹
So the nth term of the series :
1 , 1 , 2 , 3 , 4 , 9 , 8 , 27 , 16 , 81 , 32 , 243 ,64 , 729 , 128 , 2187 ,.............2ⁿ⁻¹ , 3ⁿ⁻¹
That's the final answer.
I hope it will help you.
//java program to find the nth number for the given odd even geometric progression series is:
import java.lang.Math;
import java.util.Scanner;
class Pattern4 {
static void value(double n) {
if(n%2==1)
{int x=0;
double term_in_series=(n+1)/2;
double r=Math.pow(2,term_in_series-1);
x=(int) r;
System.out.print(x);
}
if(n%2==0) {
int y=0;
double term_in_series=n/2;
double b=Math.pow(3,term_in_series-1);
y=(int) b;
System.out.print(y+" ");
}
}
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
double n=sc.nextDouble();
value(n);
}
}
//Submitted by Areeb Ali