TCS - Mock Paper 1
TCS - Mock Paper 1
TCS - Mock Paper 1
The pattern that was followed for the TCS NQT was as follows.
Numerical ability:
Data Interpretation
Statistics
Time and Work
Mensuration
Number System
Time, Speed and Distance
Ratio and Proportions
Linear Equations
Simple Interest and Compound Interest
Percentages
Profit and Loss
Verbal Ability:
Reading comprehension
Sentence correction
Sentence completion
Reasoning Ability:
Attention to detail
Unboxing a cube
Data Arrangements
Coding and Decoding
Cuts and unfolds
Venn diagrams
Blood relations
Data Interpretation
Visual reasoning
Syllogisms
Statements and Assumptions
Programming MCQ's:
Operators
Looping statements
Control statements
Arrays
Strings
Functions
Object Oriented Programming (OOPS)
Standard Template Libraries (STL)
Object Modeling
Compiler Design
Threading
Data Structures: Linked List, Stack, Queue, Trees and Graphs
Recursion
Pseudocoding
Algorithms
Basic Software Development Cycle
Coding:
Numerical Ability
Q1. A man has to travel 50 km in two hours. He could cover 20 km in one hour, and then had to stop for
10 minutes for refueling. By what factor should be increase his speed with reference to that during the
first hour so as to be able to complete the journey as per schedule?
A. 1.2
B. 1.8
C. 2.4
D. 1.5
Answer: Option B
Q2. If n is an integer such that 1nn352 is a six-digit number exactly divisible by 24, what will be the
sum of the possible values of n?
A. 15
B. 27
C. 9
D. 21
Answer: Option A
Q3. The diameter of a pizza is 30 cm. What is the area (in square cm) of the upper surface of a sector of the
pizza whose arc length is 8 cm?
A. 120 * pi
B. 60
C. 60 * pi
D. 120
Answer: Option B
Q4. What is the mean proportional (MP) between the MPs of (2/7 & 32/343) and (2 & 1/5000)?
A. 3/35
B. 4/35
C. 2/35
D. 2/175
Answer: Option C
Q5. If (x+10)% of 240 is 60% more than x% of 180, then 15% of (x+20) is what percent less than
25% of x?
A. 16
B. 15
C. 15 ½
D. 19 1/21
Answer: Option A
Q6. A sum of Rs.30000 invested in a scheme where the interest gets compounded annually and grows to
Rs. 51840 in three years. How much interest (in Rs.) would have got accrued in six months in the same
scheme had the interest been compounded quarterly?
A. 3024
B. 3075
C. 3126
D. 2975
Answer: Option B
Answer: Option C
Q8. If the positive square root of ((90^0.5)+(80^0.5) is multiplied by (2^0.5 - 1), and the product is
raised to the power of four, the result would be:
A. 1600
B. 11520000
C. 100
D. 10
Answer: Option D
Q9. What is the mean deviation of the data: 8,9,12,15,16,20,24,30,32,34?
A. 8
B. 10.2
C. 0
D. 9.2
Answer: Option A
Q10. An item was sold at a profit of 12% after giving a discount of 12.5% on the List Price. What would be
the gain or loss percentage if a discount of 25% is given on the List Price?
A. 2.5% loss
B. 2.5% gain
C. 4% gain
D. 4% loss
Answer: Option D
Q11. What is the diameter in cm of a solid right circular cylinder whose height is 6 cm and the area of
the curved surface is five times the combined area of the two flat surfaces?
A. 3
B. 2.4
C. 1.2
D. 0.9
Answer: Option B
Q13.The Variation in temperature throughout the day in a desert town was studied on the basis of the
records of the maximum and minimum temperatures which was 36 and 8 degree centigrade respectively.
What was the standard deviation in degree centigrade?
A. 28
B. 22
C. 14
D. 12
Answer: Option A
Q14. The Collection of numbers which comprise the data given below is arranged in ascending order.
(3,7,9,N - 1,15,18,19,20). If the median of the data is 12.5, what is the value of N?
A. 11
B. 12
C. 11.5
D. 10.5
Answer: Option A
Q15.A file of cadets consisting of ten rows and five columns measures 420m in length along the
direction of their marching. How much time( in hours and minutes) would it take to march for a stretch
of 3 km, if the stride of the each cadet is 80cm and he takes 57 strides per minute?
A. 1 hr 15 min
B. 1 hr 24 min
C. 1hr 10 min
D. 1 hr 20 min
Answer: Option A
Q16.96 men were engaged for a project of constructing a railway track of the length of 18km in four
weeks. After one week it was observed that the work of 4km was completed. How many additional men
should be engaged for timely completion of the project?
A. 12
B. 16
C. 14
D. 15
Answer: Option B
Q17. X is four times as efficient as Y in respect of doing a particular work. Working together they
complete the work in 16 days.In how many days Y, working alone,will be able to do half the work?
A.40
B.80
C.60
D.20
Answer: Option A
Q18. In a competitive exam, 5 marks are awarded for every correct answer and for every wrong answer,
2 marks are deducted. Sathwik and 32 marks in this examination. If 4 marks has been awarded for each
correct answer and 1 mark had been deducted for each incorrect answer, Sathwik would have scored 34
marks. If Sathwik attempted all the questions, how many questions were there in the test?
A. 20
B. 14
C. 12
D. 26
Answer: Option D
Q19. A sum invested on simple interest grows to Rs 22500 and Rs 25500 in seven and nine years
respectively. What is the rate percentage of the interest?
A. 7.5
B. 9.6
C. 13.5
D. 12.5
Answer: Option D
Q20. What is the sum (in Rs) which, when divided among X, Y, Z in the proportion 3 : 5 : 7 provided Rs.
8000 more to Z than what it would have done to him when the proportion is 11 : 15
: 19?
A. 120000
B. 180000
C. 135000
D. 175000
Answer: Option B
Answer: Option B
Q22. After purchasing two copies of the same book, X sold them respectively at 0.8 and 1.4 times their
cost prices. What was the percentage gain earned or loss incurred by X?
A. 5% gain
B. 10% gain
C. 5% loss
D. 10% loss
Answer: Option B
Q23. Two vessels X and Y of capacities one and two litres respectively are completely filled with
mixtures of two chemicals A and B. The ratio by volume of the chemicals A and B in X and Y are 3:2
and 4:5 respectively. The contents of A and B are mixed and the combination is kept in a vessel C of
capacity of four litres. How many litres of Chemical A should be added to the combination so as to make
the ratio of A to B equal to 1:1?
A. 1/135
B. 1/67
C. 1/68
D. 1/270
Answer: Option C
Q24. The marks scored by a student out of 100 in English and Mathematics at four consecutive monthly
tests held in 2019 are presented through a Bar Graph shown below. In each case the marks is a multiple
of five.
In which month is the difference of marks scored in the two subjects are highest?
A. Apr
B. Mar
C. Feb
D. Jan
Answer: Option C
Q25. The mean of set data is 5.What will be the mean if 10 is subtracted from each data.
A. 5
B. 10
C. -5
D. -15
Answer: Option C
Answer: Option B
Verbal Ability
It used to be the American shopper that exemplified the state of the world economy. The focus now
should be on the person on the other side of the till. America’s retail industry is huge: it employs 15.9
Mn workers, who represent one in nine American jobs. It is also undergoing wrenching change, as e-
commerce eats into sales. There is no more pressing test of society’s ability to cope with technology’s
impact on work.
That impact is already visible. For all the benefits that online retailing brings to consumers, it is causing
immense pain to offline rivals. Last year 4,000 American stores closed; this year more than twice that
number may shutter. Standard & Poor’s, a rating agency, expects retail defaults this year to outnumber
those in 2009, at the height of the global recession. Some formats— discount stores, groceries, high-end
malls—will continue to thrive. But many will shrink. The industry has shed 50,000 net jobs since
January. Department stores may need to close more than 800 stores to reach the productivity levels of
2006. Many outlets are looking for ways to cut labour costs by embracing automation.
Answer: Option C
Q2. What is the significant measure that stores are trying to adopt?
A. Diversifying
B. Shutdown business
C. Merging
D. Automation
Answer: Option D
Q3..Governments have been promising the eradication of child labour in high risk Industries in India for
many years. However almost 100 million children are still at work instead of going to school, and around
10 million are working in (1) Industries. India has the
biggest child population of 380million in the world; plus the (2) number of children
who are forced to earn a living.
1 - D, 2 - C
1 - B, 2 - A
1 - A, 2 - D
1 - C, 2 - B
Answer: 1 - B, 2 - A
Q4.You are going to read a text about an artist.Some sentences are missing from the text. Choose
from the list the most appropriate sentence you do not need in use.
Kahini held her first solo show in 1988, the entire proceeds of which went to the Hellen Keller Institute
for the deaf and Blind in mumbai. (1) Encountering the pathiess terrain of
inner landscape, the artist engages in a restless re-examination of idea and image.
(2) She has also taken part in several art camps.
A. In her fifth solo show with acrylic and oil-on-canvas paintings in the series titled ‘Metamorphosis’
held recently at Mumbai’s Jehangir Art Gallery, she showed for the first time her abstract work as
well.
B. Her work has been acquired by corporate houses and also forms part of private collections.
C. She has participated in a group show along with 50 women artists to celebrate International
Women’s Day.
A. (1)-A, (2)-C
Qs 5 to 9: Read the passage given below and answer questions
Twinkling lights are just visible behind screens where staff are putting the finishing touches to this year’s
Christmas displays, but in other parts of the shop, the lights are still off. John Lewis’s flagship store in
Oxford Street, central London, is bearing the scars of the pandemic.
A restaurant and cafe are closed and there are more staff than customers on the furnishings floor. The
fashion floor is also a depressing sight, with tags flagging big discounts on racks of unwanted dresses
and office wear. Last week it emerged John Lewis had applied for planning permission to convert
entire floors of this shop into office space. It’s not hard to see why.
John Lewis, with its employee ownership and reputation for stellar customer service, still holds a special
place in shoppers’ hearts. But while sister chain Waitrose, along with other supermarkets, has thrived in
the pandemic, results published last week show the department store chain is in deep trouble.Huge
changes in shopper behaviour, which have been accelerated by coronavirus, mean the John Lewis website
is now responsible for 60% of the chain’s sales – up from 30% pre-Covid. This tilt towards the web
means the department stores, as properties, are now deemed to be worth nearly £500 Mn less than before
– a reassessment in last week’s results that sent the group crashing £635 Mn into the red in the first half
of its financial year.
Answer: Option B
Answer: Option A
Q7. What unpleasant announcement will the chairman have to make to the employees?
A. That they will have a pay cut
B. That they will not get their annual bonus
C. That they will not get their salaries
D. That they will lose their jobs
Answer: Option B
Q8. How do we know that John Lewis had been in prosperous business prior to the COVID
pandemic?
A. Their website now handles 60% of their business
B. They paid an annual bonus for sixty-seven years
C. They have a new Lady Chairman
D. They were known for their customer services
Answer: Option B
Q9. Which one of the following expressions from the passage means losing money?
A. Tilt towards
B. On racks
C. Sent crashing
D. In the red
Answer: Option D
Q10. Aisha had been very successful managing her team in Edinburgh and was asked by the company to
lead a remote team for an important two-year project. Keen to demonstrate her leadership abilities to the
head office, Aisha got her team members together for a remote meeting. But right from that first meeting,
she realised that this was going to be a different challenge. (1) Lucia kept
asking about really specific details, while Aisha was hoping to use the meeting to get to know the team
members and identify priorities. Archie and Lucia kept accidentally talking at the same time, and when
they didn’t speak, there was an uncomfortable silence. Valentina hardly said a word. (2) Without these
visual clues, Aisha had no idea whether people were interested, lost, confused or bored.
A. No one had their cameras on, so there was none of the usual communication through body
language or facial expressions
B. Compared to face to face meeting the remote team is not preferred by all the managers
C. For a start,Archie was late for the meeting by about 15 minutes because of ‘technical
problems’.
1 - A, 2- C
1- B, 2- A
1- A, 2- B
1- C, 2-A
Answer: 1- C, 2-A
Q11. Fill in the blanks with the most appropriate set of words from the options given
below:
What did the painter do--------------himself from falling?
When he felt the ladder-------------he grabbed the gutter to save himself from falling
A. to save/ beginning to slip
B. to savel begin to slip
C. for saving/ began to slip
D. to save/ began slipping
Answer: Option A
Q12. One part of the sentence below may contain may error. Identify the part. If there is no error,
choose ‘No error’. Everyday life have become more complicated with the advancement in mobile
technology.
Answer: Option B
Q13. For the four sentence (S1 to S4) paragraph given below, sentences S1 & S4 are
given.From the options P,Q and R, choose appropriate sentences for S2 & S3.
P. He says that today, machinery merely helps a few to ride on the back of millions.
Q. And adds that the spinning wheel is a machinery, a little tooth-pick is a machine.
R. He observes,”How can I be against machinery when I know that even this body is a most delicate
piece of machinery?”
A. PQ
B. RQ
C. QP
D. QR
Answer: Option B
Q14. The following three sentences can be revised into one better sentence. Choose the sentence
that is the best revision:
I was at the fair. I got lost. I got scared.
A. I am scared after I am lost at the fair.
B. I went to fair and got scared as I was lost.
C. I am lost at the fair so I am too scared.
D. I got lost at the fair and was scared.
Answer: Option D
Q15. Which of the following sentences does NOT use informal language?
A. Did you locate our office quite easily?
B. You will be working with different managers during your training.
C. We shall endeavour to inform you of the position in two weeks time.
D. Is there anything else you want to ask me?
Answer: Option B
Q16. The lady purse was lost lodged a complaint at the police station.
A. Who
B. Whose
C. Whom
D. Where
Answer: Option B
Q17. You are going to read a text about a man in a photograph. Some sentences are missing from the
text. Choose from the list (A-C) the most appropriate sentence for each gap (1-2) in the text. There is one
extra sentence that you do not need to use.
It was the first photograph that i had ever seen, and its fascinated me. I still remember holding it at every
angle in order to catch the flickering light from the oil lamp on the dresser. (1) I
had never met him but I felt that I knew him. (2) I moved the photograph so that the shadow
lay perfectly around his hollow cheeks. How different he looked!
A. The man in the photograph was unsmiling, but his eyes were kind.
B. I would tell him how wonderful he looked with the shadow that I had seen across his
photograph, and I would most carefully suggest that he grew whiskers.
C. One evening when I was looking at the photograph, as I always did before I went to sleep, I noticed
a shadow across the man’s thin face.
A. (1)-A, (2)-C
B. (1)-B, (2)-A
C. (1)-C, (2)-B
D. (1)-C, (2)-A
1-C,2-D
1-D,2-B
1-A,2-A
1-B,2-C
Answer: 1-C,2-D
Q19. One part of the sentence below may contain an error. Identify the part.If there is no
error,choose ‘No error’.
The board announced that the decision to reduce the syllabus is yet to be approved by the
competent authority.
A. Is yet to be approved by the competent authority
B. No error
C. The decision is to reduce the syllabus
D. The board announced that
Answer: Option B
A. Broken up
B. Broken off
C. Broken away
D. Broken out
Answer: Option A
Q21. For the four sentence (S1 to S4) paragraph given below, sentences S1 & S4 are
given.From the options P,Q and R, choose appropriate sentences for S2 & S3.
S-1: Once upon a time an ambassador came to see the king of Sparta on some official business S-2:
S-3:
S-4:But he found nothing of that kind
P.The ambassador knew that the king of sparta was also really the ruler of entire Greece and so he
expected to see massive walls around the city for purpose of defence
Q:You are looking at the walls ten thousand men, and every man is a brick
R.After their work was over the king took his visitor on a sight-seeing tour of the capital city
A.RP
B.RQ
C.QP
D.PQ
Answer: Option D
Reasoning Ability
Q1. In each of the five pairs of the letter-clusters, the letters in the second term is a rearranged/
transformed form of the letters in the first term in a particular pattern. In which two pairs has the
transformation been done the same way?
1) MASON : AMNOS
2) PARTY : APRYT
3) FAULT : AFTLU
4) LODGE : DOLEG
5) CARGO : ACOGS
A. 2) and 3)
B. 3) and 4)
C. 1) and 3)
D. 4) and 5)
Answer: Option C
Q2. There are five rods K, L, M, N and O. The weight of L is equal to the weights of K and M taken
together. The weight of M is twice the weight of K. The weight of N is three times the weight of M. If
the weight of N is 90 kg, what will be the weight of O?
A. 120 kg
B. 60 kg
C. 105 kg
D. 90 kg
Answer: Option C
Q3. The following are the criteria of selecting a Software Engineer for an IT company.
Keith completed BCA and MCA with 76% and 72% marks respectively. He has completed 27 years of
age in the year 2019. He has secured 65% marks in the written test and 78% marks in the interview.
What decision would be taken in his case?
Answer: Option D
Q4. The figure marked ‘X’ is folded to form a box. Four possible boxes A, B, C and D are given below
some of which can be formed and some cannot be formed. Choose from the alternatives the boxes that
can be formed.
X
1
2
3
A. 1, 3 and 4 only
B. 2 and 3 only
C. 1 and 2 only
D. 2 and 4 only
Answer: Option A
Q5. Four friends A, B, C and D have one of the four professions i.e. Doctor, Architect, Engineer and
Lawyer. Each friend belongs to one of the four different cities Chandigarh, Indore, Lucknow and Pune. A
is not a lawyer or engineer. The doctor is from Lucknow. D is an architect. The lawyer is from Pune. The
engineer is neither from Chandigarh nor from Pune. D is not from Pune, C is not from Indore. Which of
the following statements is true about B?
Answer: Option A
A. FPT
B. OYC
C. JTX
D. UFI
Answer: Option D
Q7. Which of the following patterns of the boxes can be formed when the sheet given below is folded? (if the
latters are shown to indicate the sides only).
A. Only 1 and 2
B. Only 2 and 3
C. Only 2
D. Only 1, 2 and 4
Answer: Option C
Q8. A paper is folded and cut as shown below. How will it appear when unfolded?
A.
B.
C.
D.
Answer: Option D
Q9. In the following diagram, the triangle stands for ‘males’, the circle for ‘doctors’, the rectangle for
‘government employed’, the hexagon for ‘corona warriors’. The numbers in different segments show the
number of persons for that segment. How many government employed doctors are Corona warriors but
are not males?
A. 23
B. 16
C. 14
D. 7
Answer: Option B
Q10. In a certain code, A % B means ‘A is the brother of B’, A & B means ‘A is the mother of B’, A @
B means ‘A is the daughter of B’, A $ B means ‘A is the father of B’ and A # B means ‘A is the sister of
B’.
A. Sister
B. Husband
C. Wife
D. Brother
Answer: Option B
Q11 to 12. The number of employees working in six different departments of two companies A and B
are given below. Study the given data and answer the questions that follow.
Company A
Marketing 256
HR 72
Production 504
Accounts 68
Operations 256
Planning 46
Total 1202
Company B
Marketing 524
HR 108
Production 736
Accounts 122
Operations 146
Planning 58
Total 1694
Q11. If 30 employees of the Planning department quit Company B and join the Planning
department of Company A, then what is the percentage of employees in the Planning department
in the total employees in Company A?
A. 5.34%
B. 6.16%
C. 6.32%
D. 4.48%
Answer: Option B
Q12. What is the percentage difference between the employees working the Production
department of Company A and Company B?
A. 2.27%
B. 1.15%
C. 1.52%
D. 3.21%
Answer: Option C
Q13. Nehal, Iqbal, Ronit, Malin and Harbhajan participate in any one of the five activities i.e. Quiz,
Singing, Dance, Debate and Mimicry. Ronit participates in Singing. Harbhajan does not participate in
Debate and Mimicry. Malini does not participate in Mimicry. Iqbal participates in Quiz. Who
participates in Debate?
A. Malini
B. Nehal or Malini
C. Nehal
D. Cannot be determined
Answer: Option A
Q14. Select the figure that will replace the question mark in the following figure series.
A.
B.
C.
D.
Answer: Option C
Q15. Two statements are given followed by three conclusions numbered I, II and III. Assuming the
statements to be true, even if they seem to be at variance with commonly known facts, decide which of
the conclusions logically follow(s) from the statements.
Statements:
All animals are plants.
All plants are shrubs.
Conclusions:
I. Some shrubs are plants
II. Some animals are not shrubs
III. All animals are shrubs
Answer: Option B
Q16. Given below is a question followed by two statements I and II, each containing some information.
Decide which of the statements are sufficient to answer the question that follows.
How many Rs. would Shalini need to spend to buy 11 pencils and 14 pens?
Answer: Option D
Statement: Air quality has been polluted due to the increasing number of two-wheelers and four-
wheelers.
Courses of action:
I. There should be a complete ban on the sale of two-wheelers at least for the next 5 years.
II. Monitoring should take place to ensure that the vehicle’s owners get their vehicles
checked and certified for pollution-control.
III. Four wheelers cause more pollution, hence four-wheelers alone can be banned from running
on the roads.
Answer: Option B
Q18. In a certain code, K * N means K is the brother of N, K+N means K is the husband of N, K x N
means K is the mother of N and K/N means K is the sister of N.
Which of the following expression means ‘C is the daughter of Y’?
A. Y+RxH/C*V
B. Y+RxH*C/V
C. YxR+H*C/V
D. Y+RxC*H/V
Answer: Option C
Q19. Five teachers P, Q, R, S and T teach a group of students in sequence between 9 am and 2 pm.
Each teacher teaches for one hour. Q takes the first class. S teaches just after T. R teaches before P and
T. Who takes the second class from 10 am to 11 am?
A. S
B. R
C. P
D. T
Answer: Option B
Q20. Given below is a question followed by two statements, I and II, each containing some
information. Which of the following statements is/ are sufficient to answer the question?
How is A related to C?
Statements:
I. A is the wife of B and B is the brother of C.
II. C is the son of D.
Answer: Option B
Q21. Given below is a question followed by two statements, II and II, each containing some information.
Decide which of the statements are sufficient to answer the question.
Five friends A, B, C, D and E are sitting in a line facing North. Who is sitting exactly in the
middle?
I. C is sitting between A and B. E is at the fourth place to the left of B.
II. E is sitting to the immediate left of D. C is to the immediate left of B.
Answer: Option B
Programming Logic
Q1..Given here is a scenario. Consider the graph algorithm and answer the given question.
John wants to go to different locations of the city in which he is. He has listed all of them
down.However he wants to visit one location before visiting some other location What
application of graphs he uses to determine that location?
A. DFS
B. Dijkstra’s
C. BFS
D. Topological Sorting
Answer: Option D
int $ = 5;
}
}
Answer: Option A
Q3. What will be printed if the below sample code is executed? Enter your answer only as a
NUMERAl
class main
{
public static void main(string args[]}
{
int i,j,x=0;
for(i=0;i<5;i++)
for(j=0;j<5;j++){
x=(i+j-1);
System.out.print(x);
break;
}
}
System.out.print(x);
}
Answer: -101233
Q5. There are two integer numbers X and Y that are between 0 to 25. User stores the value under a 5
bit number. How many minimum bits are required to store the result of the below expression?
Res=3*(X-Y)
A.8
B.5
C.7
D.8
Answer: Option D
Explanation: If we perform X-Y the possible answers shall be from -75 to 75. In order to store this
we need 8 bits.
Q6. Find Prefix and suffix for the below infix problem statement :
Infix Expression : 11 +20/5*(20-15)^6^5
Answer: Option D
Q7. Write the name of a library of functions which is used to perform arithmetic operations on
BigInteger and BigDecimal.
Answer: Option B
Answer: Option B
Coding
Q1. Selection of MPCS exams include a fitness test which is conducted on ground.There will be a batch
of 3 trainees,appearing for a running test on track for 3 rounds.
You need to record their oxygen level after every round.After trainees are finished with all rounds,
calculate for each trainee his average oxygen level over the 3 rounds and select the one with the
highest average oxygen level as the most fit trainee. If more than one trainee attains the same highest
average level,they all need to be selected. Display the most fit trainee(or trainers) and the highest
average oxygen level.
Note:
1.The oxygen value entered should not be accepted if it is not in the range between 1 and 100. 2.If the
calculated maximum average oxygen value of the trainees is below 70 then declare the trainees as unfit
with meaningful message as “All trainees are unfit”
3.Average oxygen values should be rounded
Example 1:
INPUT Values
95
92
95
92
90
92
90
92
90
OUTPUT Values
Trainee Number: 1
Trainee Number ;3
Note:Input should be 9 integer values representing oxygen levels entered in order as Round
1:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Round 2:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Round 3:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Oxygen must be in given format as in above example.For any wrong input final output should display
“INVALID INPUT”
Solution in C++:
Q2. There is jar full of candies for sale at a mall counter. JAr has the capacity N, that is JAR can contain
maximum N Candies when JAR is full. At any point of time,JAR can have M number of candies where
M<=N. Candies are served to the customers. JAR is never remaining empty as when last K candidates are
left,JAR is refilled with new candidates in such a way that JAR gets full.
Write the code to implement above scenario.Display JAR at counter with available number of candies.
Input should be number of candies one customer orders at point of time. Update the JAR after every
purchase and display JAR at counter.Output should give number of candies sold and updated number of
candies in JAR. If input is more than number of candies in JAR,return “INVALID INPUT”. Given,
N=10, Where N is number of candies available, K<=5,Where K is number of minimum candies that
must be inside JAR ever.
Example1: (N=10,K=<5)
Input Value
3
Output Values:
Number of Candies Sold: 3
Number of Candies available:7
Solution in C++:
#include <iostream.h>
using namespace std;
int main()
{
int n=10, k=5;
int num;
cin>>num;
if(num>=1 && num<=5)
{
cout<< "NUMBER OF CANDIES SOLD : "<<num<<"\n";
cout<<"NUMBER OF CANDIES LEFT : "<<n-num;
}
else
{
cout<<"INVALID INPUT\n";
cout<<"NUMBER OF CANDIES LEFT : "<<n;
}
return 0;
}