Hello friends, here is the mostly asked questions and answers in TCS Exam. Please go through it and prepare well. Best Luck.
1) Hazecraft Client Series
The Event Organizing Company "Hazecraft" focuses on event management in a way that creates a win-win situation for all involved stakeholders. Hazecraft doesn't look at building one time associations with clients but aim at creating long-lasting collaborations that will span years to come. This goal of the company has helped them to evolve and gain more clients within a notable time.
The number of clients of the company from the start day of their journey till now is recorded sensibly and is seemed to have followed a specific series like 2,3,5,7,11,13,17,19, 23,…, etc
Write a program that takes an integer N as the input and will output the series till the Nth term.
Note:
The given series is prime number series.
Input Format:
The first line of the input is an integer N.
Output Format:
The output is a single line series till Nth term, each separated by a space.
Refer sample input and output for formatting specifications.
Sample Input 1:
5
Sample Output 1:
2 3 5 7 11
Sample Input 2:
10
Sample Output 2:
2 3 5 7 11 13 17 19 23 29
Solution :-
import java.util.*;
public class Main{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int count =0;
boolean a;
System.out.print("2 ");
for(int i =3; n>1;i++)
{
a=isPrime(i);
if(a)
{
System.out.print(i+" ");
n--;
}
}
}
public static boolean isPrime(int n)
{
int count=0;
for(int i =1;i<=n;i++ )
{
if(n%i==0)
{
count++;
}
}
if(count==2)
{
return true;
}
else
{
return false;
}
}
}
Don't Copy Learner
Output :
S.No | Test | Expected | Obtained | Differences |
1 | Input: 10 | 2 3 5 7 11 13 17 19 23 29 | 2 3 5 7 11 13 17 19 23 29 | |
2 | Input: 5 | 2 3 5 7 11 | 2 3 5 7 11 |
2) Mark's Scholarship
Mark studies at Teswan National University. Now is the time for exam results. Mark hopes that his scores in 5 subjects in the exam could fetch him a scholarship for his GRE preparation.
The following simple rules are used to find whether he is eligible to receive the scholarship:
- The University follows 5 point grading system. In an exam, a student can receive any score from 2 to 5. 2 is called an F grade, meaning that the student has failed that exam.
- The student should not have failed any of the exams.
- The Student must obtain a full score in some of his/her exams to show that he/she is excellent in some of the subjects.
- He/She must have a grade point average not less than 4.
You are given information regarding how Mark performed in those 5 subjects. Write a program to check whether he will receive the scholarship or not.
Input Format:
The input contains 5 integers denoting Mark’s 5 subjects score in the exam.
Output Format:
Output a single line - "Yes" (without quotes) if Mark will receive the scholarship, otherwise "No" (without quotes).
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to the output.]
Sample Input and Output 1:
Enter the subject 1 mark
3
Enter the subject 2 mark
5
Enter the subject 3 mark
4
Enter the subject 4 mark
4
Enter the subject 5 mark
3
No
Sample Input and Output 2:
Enter the subject 1 mark
3
Enter the subject 2 mark
4
Enter the subject 3 mark
4
Enter the subject 4 mark
4
Enter the subject 5 mark
5
Yes
Don't Copy Learner
S.No | Test | Expected | Obtained | Differences |
1 | Input: 3 5 4 4 3 | Enter the subject 1 mark Enter the subject 2 mark Enter the subject 3 mark Enter the subject 4 mark Enter the subject 5 mark No | Enter the subject 1 mark Enter the subject 2 mark Enter the subject 3 mark Enter the subject 4 mark Enter the subject 5 mark No | |
2 | Input: 3 4 4 4 5 | Enter the subject 1 mark Enter the subject 2 mark Enter the subject 3 mark Enter the subject 4 mark Enter the subject 5 mark Yes | Enter the subject 1 mark Enter the subject 2 mark Enter the subject 3 mark Enter the subject 4 mark Enter the subject 5 mark Yes |
Don't Copy Learner
3) Star Pattern
Write a program to generate a pattern of stars.
Input and Output Format:
Input consists of a single integer that corresponds to n, the number of rows.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to the output.]
Sample Input and Output 1:
5
*
**
***
****
*****
Sample Input and Output 2:
3
*
**
***
Solution :-
import java.util.*;
import java.io.*;
class Main{
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.print("");
int n = sc.nextInt();
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Output :
S.No | Test | Expected | Obtained | Differences |
1 | Input: 5 | * ** *** **** ***** | * ** *** **** ***** | |
2 | Input: 3 | * ** *** | * ** *** |
Thank You so Much !
ReplyDelete