Skip to main content

Posts

Showing posts with the label nth term of an AP

nth term of an AP[BASIC]

Given the first 2 terms of Arithmetic Series tell the nth term of the series.  Input: First line contains an integer, the number of test cases 'T'. Each test case in its first line should contain two positive integer a and b(First 2 terms of AP). In the second line of every test case it contains of an integer N. Output: In each seperate line print the Nth term of the Arithmetic Progression. Constraints: 1<=T<=30 -100<=a<=100 -100<=b<=100 1 <= N <= 100 Example: Input: 2 2 3 4 1 2 10 Output: 5 10 CODE: import java.util.*; import java.lang.*; import java.io.*; class GFG { public static void main (String[] args) { Scanner sc = new Scanner (System.in); int m =sc.nextInt(); for(int mi=0;mi<m;mi++){     int a=sc.nextInt();     int b = sc.nextInt();     int d= b-a;     int n =sc.nextInt();     System.out.println(a+(n-1)*d); ...