Problem statement
Implement the following function:
int Sum(int n, int m);
The function accepts two integers 'n' and 'm' as its argument. Implement the function to find the sum of every nth number in the range from 1 to 'm' (both inclusive) and return the sum.
Assumption:
n > 0 and m > n
Sum lies within integer range.
Example:
Input:
n. 2.
m: 10
Output:
30
Explanation:
Since n = 2, sum of every 2nd number up to 10 is 2 + 4 + 6 + 8 + 10 = 30, thus output is 30
Answers
Answered by
0
Answer:
Input : 3
Output : 9
Explanation: So here the tern of the sequence upto n = 3 are:1, 3, 5 And hence the required sum is = 1 + 3 + 5 = 9
Input : 6
Output : 36
Similar questions