problem 2:Given the first 2 terms A1 and A2 of an Arithmetic Series.Find the Nth term of the series.

 QUESTION:

 

Series AP
School

Given the first 2 terms A1 and A2 of an Arithmetic Series.Find the Nth term of the series. 

Example 1:

Input:
A1=2
A2=3
N=4
Output:
5
Explanation:
The series is 2,3,4,5,6....
Thus,4th term is 5.

 

ANSWER:

 

int nthTermOfAP(int A1, int A2, int N) {
      int result;
      int diff=A2-A1;
      result=A1+(N-1)*diff;
      return result;
    }

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.