 # TCS NQT BLOCK CALCULATION CODING PROBLEM

TCS NQT BLOCK CALCULATION CODING PROBLEM

We at gradjobopenings.com provide free job alerts of freshers job drives. In this website we list on campus job openings for freshers and off campus job openings for freshers and also work from home job openings. This is the best website to apply for off campus drive in India. Visit our website for government job alerts and private job alerts. We also list free interview notes and study materials, one of the best interview study website.comfortable to face the interviews:

In a puzzle game, there are five blocks. Each block is assigned with some repeating numbers.

The number 1 starts from block-1, 2 on block-2, 3 on block -3, 4 on block-4 and 5 on block-5. Again 6 on block-4 and so on.

Here we observe a pattern, the numbers 10, 8 and 2 are on block-2 , 3, 7 and 11 on the block 3 and so on.

Given a positive integer N. The task is to find the correct block to which the number assigned.

**Input format**:

First line – A single positive integer N.

**Output format**:

A single positive integer denoting the block number which N belongs to.

**Examples**

– Input :

3   —> Value of N

– Output :

3    -> Block number

– Input :

16    —> Value of N

– Output :

2    —> Block number

Program in C

``````#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int r = n % 8;
if (r == 0)
printf("2");
else if (r < 5)
printf("%d", r);
else
printf("%d", 10 - r);
return 0;
}
``````

Program in C++

``````#include <iostream>
int main() {
int n;
std::cin >> n;
int r = n % 8;
if (r == 0)
std::cout << 2;
else if (r < 5)
std::cout << r;
else
std::cout << 10 - r;
return 0;
}
``````

Program in Java

``````import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.close();
int r = n % 8;
if(r == 0)
System.out.print(2);
else if( r < 5 )
System.out.print(r);
else
System.out.print(10 - r);
}
}
``````

Program in Python

``````if __name__ == '__main__':
n = int(input())
r = n % 8
if r == 0:
print(2, end = '')
elif r < 5:
print(r, end = '')
else:
print(10 - r, end = '')
``````