TCS Coding Question | Find the 15th term of the series? 0,0,7,6,14,12,21,18 ...

 Find the 15th term of the series? 0,0,7,6,14,12,21,18....





This series is a mixture of 2 series, all the odd terms in this series form Multiplication of 7 starting from 0  and every even terms forms a multiplication of 6 starting from 0. Write a program to find the nth term in this series.


The value n in a positive integer that should be read from STDIN the nth term that is calculated by the program should be written to STDOUT. Other than the value of the nth term no other characters /strings or message should be written to STDOUT.

C Program
#include <stdio.h>

int main(void) {
  int n;
  int res = 0;
  scanf("%d",&n);
  if(n%2==0){
  	for(int i=0 ;i < n/2-1;i++){
		res += 6;
	}
	printf("%d",res);
  } else {
  	for(int i=0 ;i < n/2-1;i++){
		res += 7;
	}
	printf("%d",res);
  }
  return 0;
}

Java Program

import java.util.*;

public class NumberSeries {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int res = 0;
		int input = sc.nextInt();
		if (input % 2 == 0) {
			for (int i = 0; i < input / 2 - 1; i++) {
				res += 6;
			}
		} else {
			for (int i = 0; i < input / 2 - 1; i++) {
				res += 7;
			}
		}
		System.out.println(res);
	}

}


For More TCS Digital Capability Assessment solution - Click here  or Here


This Blog is Hard work !

Can you give me a treat 😌



Post a Comment

0 Comments