0% found this document useful (0 votes)
59 views

C Language - Questions

The document describes 7 programming problems involving functions and pointers in C language. The problems involve tasks like identifying if a number is odd or even using functions, merging and sorting arrays passed by pointer, finding minimum and maximum elements in an array passed by pointer, calculating parking charges based on vehicle type, exchanging first and last elements of an array passed by pointer, checking if a group of friends can enroll in a course based on capacity, and determining the winner of a billiards game based on maximum lead during rounds.

Uploaded by

Anshu Raj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

C Language - Questions

The document describes 7 programming problems involving functions and pointers in C language. The problems involve tasks like identifying if a number is odd or even using functions, merging and sorting arrays passed by pointer, finding minimum and maximum elements in an array passed by pointer, calculating parking charges based on vehicle type, exchanging first and last elements of an array passed by pointer, checking if a group of friends can enroll in a course based on capacity, and determining the winner of a billiards game based on maximum lead during rounds.

Uploaded by

Anshu Raj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Problem

Get an integer value in main function.


a. Find whether the given number is odd or even using two different user defined
functions.
b. First user defined function should identify whether the argument passed is odd
or not, and return result to main function.
c. Second user defined function should identify whether the argument passed is
even or not and return result to main function. Print the result in main
function.
d. Apply mutual recursion between the user defined functions.

2. Problem
A statistician reads two sets of data for his research work. Set A = {women’s height in
centimeters}. Set B = {men’s height in centimeters}. Each set contains five data.
a. He is passing both the set of data to a function using the base address of the
dataset A & B.
b. Inside the function he merges all people heights and producing the result in
increasing order.
c. The ordered height should be displayed in main.
d. Use pointer notation to access the data.

3. Problem
Write a function that receives 3 arguments – an array of numbers, 2 variables – small
and large.

a. The function finds the largest and the smallest element in the array and stores
them in the corresponding variables passed as arguments.
b. Call this function from the main program by passing all the arguments by
pointer and print the result in the main program.

Do not return any values from the function back to the calling program.
4. Problem

Write a function to calculate parking charges of a vehicle. Enter the type of vehicle as
character (c- car, b- bus, t-two wheeler..etc) and number of parking hours then calculate
the charges as given: bus- 20 rupees per hour, car- 10 rupees per hour, two wheelers- 5
rupees per hour.

5. Problem

C program to accept an array of elements as input (numeric or character).

a. Pass this array by pointer to a function.


b. Inside the function, exchange the first character with last character, second with
last but one and so on.
c. Print the elements of the array after exchange in the main program.

6. Problem
There is a group of N friends who wish to enroll in a course together. The course has a
maximum capacity of M students that can register for it. If there are K other students who
have already enrolled in the course, determine if it will still be possible for all the N friends to
do so or not.

Input Format

 The first line contains a single integer T - the number of test cases. Then the test cases
follow.
 Each test case consists of a single line containing three integers N, M and K - the size
of the friend group, the capacity of the course and the number of students already
registered for the course.

Output Format

For each test case, output Yes if it will be possible for all the N friends to register for the
course. Otherwise output No.
You may print each character of Yes and No in uppercase or lowercase (for example, yes,
yEs, YES will be considered identical).

Constraints

 1≤T≤1000
 1≤N≤M≤100
 0≤K≤M

Sample 1:

Input
Output
3
2 50 27
5 40 38
100 100 0
Yes
No
Yes

Explanation:

Test Case 1: The 2 friends can enroll in the course as it has enough seats to accommodate
them and the 27 other students at the same time.

Test Case 2: The course does not have enough seats to accommodate the 5 friends and the 38
other students at the same time.

7. Problem
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the
transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the
withdrawal transaction (including bank charges). For each successful withdrawal the bank
charges 0.50 $US.

Calculate Pooja's account balance after an attempted transaction.

Input

Positive integer 0 <X<= 2000 - the amount of cash which Pooja wishes to withdraw.

Nonnegative number 0<= Y<= 2000 with two digits of precision - Pooja's initial account
balance.

Output
Output the account balance after the attempted transaction, given as a number with two digits
of precision. If there is not enough money in the account to complete the transaction, output
the current bank balance.

Example - Successful Transaction


Input:
30 120.00

Output:
89.50

Example - Incorrect Withdrawal Amount (not multiple of 5)


Input:
42 120.00

Output:
120.00

Example - Insufficient Funds


Input:
300 120.00

Output:
120.00

8. Problem
The game of billiards involves two players knocking 3 balls around on a green baize table.
Well, there is more to it, but for our purposes this is sufficient.

The game consists of several rounds and in each round both players obtain a score, based on
how well they played. Once all the rounds have been played, the total score of each player is
determined by adding up the scores in all the rounds and the player with the higher total score
is declared the winner.

The Siruseri Sports Club organises an annual billiards game where the top two players of
Siruseri play against each other. The Manager of Siruseri Sports Club decided to add his own
twist to the game by changing the rules for determining the winner. In his version, at the end
of each round, the cumulative score for each player is calculated, and the leader and her
current lead are found. Once all the rounds are over the player who had the maximum lead at
the end of any round in the game is declared the winner.

Consider the following score sheet for a game with 5 rounds:

Round Player 1 Player 2

1 140 82
2 89 134

3 90 110

4 112 106

5 88 90

The total scores of both players, the leader and the lead after each round for this game is
given below:

Round Player 1 Player 2 Leader Lead

1 140 82 Player 1 58

2 229 216 Player 1 13

3 319 326 Player 2 7

4 431 432 Player 2 1

5 519 522 Player 2 3

Note that the above table contains the cumulative scores.

The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1)
during the game.

Your task is to help the Manager find the winner and the winning lead. You may assume that
the scores will be such that there will always be a single winner. That is, there are no ties.

Input

The first line of the input will contain a single integer N (N ≤ 10000) indicating the number
of rounds in the game. Lines 2,3,...,N+1 describe the scores of the two players in the N
rounds. Line i+1 contains two integer Si and Ti, the scores of the Player 1 and 2 respectively,
in round i. You may assume that 1 ≤ Si ≤ 1000 and 1 ≤ Ti ≤ 1000.

Output

Your output must consist of a single line containing two integers W and L, where W is 1 or 2
and indicates the winner and L is the maximum lead attained by the winner.

Sample 1:

Input

5
140 82
89 134
90 110
112 106
88 90

Output
1 58

You might also like