Skip to main content

TCS NQT 2020 EXAM - Coding Section Solutions for all batches

Tcs NQT 2020 exam -  coding section solutions for all slots : 


NOTE: GitHub source code available for all questions in C, C++ and in python programming languages  click here :




SLOT: 1

NOTE: Time is 30 minutes to solve this problem using any of these programming languages c, c+ +, java, Perl, python 2.7

Problem statement
One programming language has the following keywords that cannot be used as identifiers:

break, case, continue, default, defer else, for, func, goto, if, map, range, return, Struct, type, var

Write a program to find if the given word is keyword or not

Example-1

Input: defer
Expected Output: defer is a keyword

Example-2

Input: While
Expected Output: while is not a keyword

PROGRAM IN C++ :


#include <iostream>

using namespace std;

int main()
{
    string data;
    cin>>data;

    if(data == "break"    || data == "case" 
    ||data == "continue"  ||data == "default"
    ||data == "defer"     ||data == "else" 
    ||data == "for"       ||data == "func" 
    ||data == "goto"      ||data == "if"
    ||data == "map"       ||data == "range"
    ||data == "return"    ||data == "struct" 
    ||data == "type"      ||data == "var")
    
    cout<<data<<" is a keyword";
    else
    cout<<data<<" is not a keyword";


    return 0;
}



SLOT: 2

Write a program to find the difference between the sum of the digits in the even places and sum of the digits in the odd places

Problem description 
int the number 5179
odd place terms are : (5+7) = 12
even place terms are : (1+9) = 10
result :  12 - 10 = 2

Example-1

Input: 5179
Expected Output: 2

Example-2

Input: 718
Expected Output: 14


PROGRAM IN C++ :


#include <iostream>
#include <cstring>

using namespace std;

int main() 
{ 
 int number; 
 cin>>number;
 int even = 0 , odd = 0 ;
        int checker = 1 , result = 0;
 
 while(number != 0) {
     
     if (checker % 2 == 0) 
            even += number % 10;   
        else
            odd += number % 10;   
        number /= 10; 
        checker++;
 }
 
 result = even - odd;
 if( result > 0)
 cout<<result;
 else
 cout<< -1 * result;

 return 0; 
}


SLOT: 3

Write a program to convert a decimal number in the base 17 to a decimal number in base 10 :

Problem statement
 apply decimal conversion logic to solve this problem, where 0 - 9 digits are same, while replace A B C D E F G with 10 11 12 13 14 15 16 respectively in the given input and do the conversion accordingly

Example-1

Input: 1A
Expected Output: 27

Example-2

Input: 23GF
Expected Output: 10980


PROGRAM IN C++ :

#include <iostream>
#include <cstring>

using namespace std;


int val(char c) 
{ 
 if (c >= '0' && c <= '9') 
  return (int)c - '0'; 
 else
  return (int)c - 'A' + 10; 
} 


int toDeci(char *str) 
{      
      int base = 17 ;
 int len = strlen(str); 
 int power = 1; 
 int num = 0; 
 int i; 


 for (i = len - 1; i >= 0; i--) 
 { 
   num += val(str[i]) * power; 
   power = power * base; 
 } 

 return num; 
} 

int main() 
{ 
 char str[50]; 
 cin>>str;
        cout<<toDeci(str); 
 return 0; 
}


SLOT: 4

Write a program to find the nth value in the series. 

Problem description 
here position starts at ( 0,0 ) and it will move in the direction right, top, left , bottom at the multiples of 10 . ( consider a graph with origin and directions as x, y, -x, -y on moving in x, y it will be positive term and in -x and - y it will be in negative terms )


Example-1

Input: 1
Expected Output: (10,0)

Example-2

Input: 4
Expected Output: (-20 , -20 )


Example-3

Input: 3

Expected Output: (-20 , 20 )


PROGRAM IN C++ :

#include <iostream>

using namespace std;

int values(int n){
    int x =0 , y = 0 , rem = 0;
    for (int i = 0 ; i < n ; i++)
    {
        rem = i % 4;
        if (rem == 0)
            x = x + 10*(i+1);
        else if (rem == 1)
            y = y + 10*(i+1);
        else if (rem == 2)
            x = x - 10*(i+1);
        else if (rem == 3)
            y = y - 10*(i+1);
    }
    cout<<x<<","<<y;

}
int main()
{
    int number;
    cin>>number;
    values(number);
    return 0;
}

Comments

  1. #include

    using namespace std;

    void values(int n){ //change the function with return type void
    int x =0 , y = 0 , rem = 0;
    for (int i = 0 ; i < n ; i++)
    {
    rem = i % 4;
    if (rem == 0)
    x = x + 10*(i+1);
    else if (rem == 1)
    y = y + 10*(i+1);
    else if (rem == 2)
    x = x - 10*(i+1);
    else if (rem == 3)
    y = y - 10*(i+1);
    }
    cout<>number;
    values(number);
    return 0;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Learn c++ in Tamil | Complete guide and tutorial | Beginner to Advance all concepts explained.

hi guys welcome , all the coding used in video are available here : /* hi guys welcome to learn c++ in tamil what is C++ how what software your own program schools,clg,institute.... start 1.interest 2.patience 3.fun 4.practise computer program - app - programming source code - hardware - fb running , executing machine language :  101010 assembly lang : mov h1; high lang : c , c++....java , js , python  eg :  a+b .....1001010  compiler :  human to machine              machine to human  rules :  a+b;  usage:  games, manufacturing , embedded , finance , graphics , etc...  Guide: 1.problem 2.solution - alternative 3.program  - C++ 4.compile  - turboc , ide , codeblocks , cmd 5.result   - library file - linker : #include<iostream.h>    input , output std::cout<<"welcome";   standard character out << " "; primary section : 1.statements   ;  end 2.functions   main() 3.syntax  , syntax error pra

Get Ethical Hacking Project #1

Thanks for your interest in our course This is a paid course, 150 rs for Indian people, 5$ for international people Instructions to get course: Indian people can get the course by paying using this UPI id   tamilhacks@ybl  (KARTHIKEYAN T) send 150 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)     The above mentioned method is most preferable. if you don't have a upi id app, install  phonepe  or  google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100 Rs for tax and other charges here )   After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that . the course is in zip format, so after downloading the file extra

Xplore-Know your TCS Solutions

KNOW YOUR TCS-SOLUTIONS 1.Who is the founder of Tata group? Jamsetji Tata 2.Which characteristics of Big Data deals with trustworthiness of data? Veracity 3.Which is India's first indigeneously designed and manufactured car? Tata Indica 4.What was originally called the "Imitation game" by its creator? The Turing test 5.90% of world's data is created in the last 2 years. True 6.In 1990s,which company did Tata steel acquire? Corus 7.How many independently operating companies are there under Tata group? Over 100 8.We use natural language processing for reviewing twitter fields. True 9.The change of mind set is required from "optimizing scarce resources" to "harnessing abundance" will help in? Leveraging ecosystems 10.Robots can be used for building houses. True 11.Which among the following key for IT management is based on the proper use of data? Embedding security in every system. 12.When did Tata Motors unveil Tata Nano? 2008 13.Business 4.0 brings