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

Assignment-3 (1)

Uploaded by

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

Assignment-3 (1)

Uploaded by

apujan2430295
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

9.

Program that will categorize a single character that is entered at the terminal, whether it is *
an alphabet, a digit or a special character.

(Restriction: Without math.h)

Sample input Sample output


z Alphabet
A Alphabet
8 Digit
* Special

10. Program that will evaluate simple expressions of the form- **

<number1> <operator> <number2>

; where operators are (+, - , *, /)

And if the operator is “/”, then check if <number2> nonzero or not.

Sample input Sample output


100 * 55.5 Multiplication: 5550
100 / -5.5 Division: -18.181818
100 / 0 Division: Zero as divisor is not valid!

11. Program that will take the final score of a student in a particular subject as input and find *
his/her grade.

Marks Letter Grade Marks Letter Grade Marks Letter Grade


90-100 A 70-73 C+ Less than 55 F
86-89 A- 66-69 C
82-85 B+ 62-65 C-
78-81 B 58-61 D+
74-77 B- 55-57 D

Sample input Sample output


91.5 Grade: A
50 Grade: F
12. Program that will construct a menu for performing arithmetic operations. The user will give *
two real numbers (a, b) on which the arithmetic operations will be performed and an integer
number (1 <= Choice <= 4) as a choice. Choice-1, 2, 3, 4 are for performing addition,
subtraction, multiplication, division (quotient) respectively.

Sample input (a, b, Choice) Sample output


5 10 Multiplication: 50
3
-5 10.5 Quotient: 0
4

13. Program that will construct a menu for performing arithmetic operations. The user will give **
two real numbers (a, b) on which the arithmetic operations will be performed and an integer
number (1 <= Choice <= 4) as a choice. Choice-1, 2, 3, 4 are for performing addition,
subtraction, multiplication, division respectively.

If Choice-4 is selected, again the program will ask for another choice (1 <= Case <=2), where
Case-1, 2 evaluate quotient and remainder respectively.

Sample input Sample output


5 10 Multiplication: 50
3
-5 10.5 Quotient: 0
4
1
-5 10.5 Remainder: -48
4
2

1. Addition
2. Subtraction
3. Multiplication
4. Division

1. Quotient
2. Remainder
14. Program that will construct a menu for performing arithmetic operations. The user will give ***
two real numbers (a, b) on which the arithmetic operations will be performed and an integer
number (1 <= Choice <= 4) as a choice. Choice-1, 2, 3, 4 are for performing addition,
subtraction, multiplication, division respectively.

If Choice-4 is selected, the program will check if b is nonzero.

If the check is true, the program will ask for another choice (1 <= Case <=2), where Case-1, 2
evaluate quotient and reminder respectively. If the check is false, it will print an error
message “Error: Divisor is zero” and halt.

Sample input Sample output


5 10 Multiplication: 50
3
-5 10.5 Reminder: -48
4
2
-5 0 Error: Divisor is zero
4

15. Program for “Guessing Game”: ***


Player-1 picks a number X and Player-2 has to guess that number within N = 3 tries. For each
wrong guess by Player-2, the program prints “Wrong, N-1 Chance(s) Left!” If Player-2
successfully guesses the number, the program prints “Right, Player-2 wins!” and stops
allowing further tries (if any left). Otherwise after the completion of N = 3 wrong tries, the
program prints “Player-1 wins!” and halts.

[ Restriction: Without using loop/break/continue


Hint: Use flag ]

Sample input Sample output


(X, n1, n2, n3)
5 Wrong, 2 Chance(s) Left!
12 8 5 Wrong, 1 Chance(s) Left!
Right, Player-2 wins!
100 Wrong, 2 Chance(s) Left!
50 100 Right, Player-2 wins!
20 Wrong, 2 Chance(s) Left!
12 8 5 Wrong, 1 Chance(s) Left!
Wrong, 0 Chance(s) Left!
Player-1 wins!
Computer-Based Examination (25 min)

10
Transportation Service Charge Calculator

You are tasked with developing a program for a local transportation company. The
company offers different types of transportation services, each with a different charge per
kilometer. The services and their respective charges are as follows:

● Car: 500 Taka per kilometer


● Bus: 300 Taka per kilometer
● Bike: 100 Taka per kilometer

Write a C program that:

1. Asks the user to choose a service by entering 1 for Car, 2 for Bus, or 3 for Bike.
2. Then, asks the user to input the number of kilometres they want to travel.
3. Calculates the total charge based on the selected service and distance.
4. Prints the total charge and service type.

You need to complete the program (uses of switch-case will be appreciated).

Input 1 Output 1

Select the service: You selected Bus.


1. Car The total charge for your trip is: 750.00
2. Bus
3. Bike
Enter your choice: 2
Enter the distance: 2.5

Input 2 Output 2

Select the service: Invalid service type selected.


1. Car
2. Bus
3. Bike
Enter your choice: 5
Enter the distance: 5
Computer-Based Examination (25 min)

10
Internet Data Package Cost Calculator
You are tasked with developing a program for an internet service provider. The company
offers different types of data packages, each with a different charge per GB. The packages
and their respective charges are as follows:

● Basic Package: 50 Taka per GB


● Standard Package: 100 Taka per GB
● Premium Package: 150 Taka per GB

Write a C program that:

1. Ask the user to choose a package by entering 1 for Basic, 2 for Standard, or 3 for
Premium.
2. Ask the user to input the number of GBs they want to use.
3. Calculates the total cost based on the selected package and data usage.
4. Prints the total cost and the selected package type.

You need to complete the program using if-else statements.

Input 1 Output 1

Select the data package: You selected the Premium Package.


1. Basic Package The total charge for your package is:
2. Standard Package 7500.00
3. Premium Package
Enter your choice: 3
Enter the number of GBs you want to use: 50

Input 2 Output 2

Select the data package: Invalid package type selected.


1. Basic Package
2. Standard Package
3. Premium Package
Enter your choice: 4
1

Note: Answer all the questions.


1. Einstein’s equation for the theory of relativity is as follows: 𝐸 = 𝑚𝑐
2 [5]
where E = energy, m = mass, c = Speed of light
Write a C program that will take 2 floats (Energy and mass) as input, and print
the Speed of Light as output to 3 decimal places.

Sample Input Sample Output


134.5 150.2 0.946
84.9 12.6 2.596

2. Write a C program that can calculate the area and perimeter of a rectangle. The [5]
system first takes input of a character that can be ‘A’ or ‘P’. If A is entered, the
program will compute area, and if P is entered, the program will compute
perimeter. To compute, the program needs to take two floating point numbers,
length and width first.

Formulas:
● Area of a rectangle: length * width
● Perimeter of the rectangle: 2* (length + width)

Sample Input Sample Output

A 5.0 4.0 The area of a rectangle is: 20.000000

P 3.0 2.0 The perimeter of the rectangle is:


10.000000

3. Take three integers as input and find the maximum value. If the maximum [5]
number is divisible by 2 print “Red Number”, or if it is divisible by 3, print “Blue
number”, or if divisible by both 2 and 3 print, “Purple number” or if it is divisible
by neither print “White number”.

Sample Input Sample Output

34 45 40 Blue Number
10 9 7 Red Number

4. Write a C program that will take three integer numbers as input, and calculate the [5]
maximum value after using exactly one addition and exactly one multiplication
operation among those numbers. [Hints: Compute values for all three possible
combinations (a+ b*c), (b+a*c), and (c+a*b) and find the maximum value.]

Sample Input Sample Output

1 4 7 Maximum value: 29

-5 0 3 Maximum value: 3

-3 -2 -9 Maximum value: 25

5. Write a program that will take a positive integer as input, find the last digit, and [5]
print all the digits from the last digit to digit 9. You must use switch case
statements and the last digit as its input.

Sample Input Sample Output

54 456789

90 0123456789

9 9

16 6789
2

Note: Answer all the questions.


1. 4 3 [5]
The volume of a Sphere is given by the formula: 𝑉 = 3
π𝑟 and the surface
2
area of a Sphere is given by the formula: 𝐴 = 4π𝑟 , where r = Radius of
Sphere. Write a program that will take the radius of a sphere as input, and
compute and print the volume and surface area of the sphere. (π = 3. 1416).
Sample Input Sample Output

10.5 Volume = 4849.06 , Area = 1385.45

12.9 Volume = 8992.05 , Area = 2091.17

2. A function f(x,y) can be defined as follows: [5]


3
𝑥 + 5𝑥𝑦 ; 𝑥, 𝑦 < 0
𝑓(𝑥, 𝑦) = 4𝑦 ; 𝑥 < 0 𝑎𝑛𝑑 𝑦 > 0
1
(𝑥+𝑦)
; 𝑥 ≥0
Write a C program to evaluate f(x,y) following above definition. For values that
are not in the mentioned range your program should output “Undefined”.

Sample Input Sample Output

-3.8 -2.2 -13.072

-0.6 0 Undefined

52 0.143

3. Take three integers as input and find the minimum among them. If the [5]
minimum number is odd, print “Red Number”, otherwise print “Blue number”.
Sample Input Sample Output

34 45 40 Even, Blue Number

11 15 17 Odd, Red Number


4. Write a C program that asks the user to input three numbers representing the [5]
lengths of the sides of a triangle. Using if/else statements, determine and print
whether the triangle is valid or not. If the triangle is valid, then print “Valid
Triangle.”. If the triangle is invalid, print “Invalid Triangle.”
[Hints: A triangle is valid if the sum of its two sides is greater than the third
side.]
Sample Input Sample Output

2 9 10 Valid Triangle.

1 2 3 Invalid Triangle.

5. Write a program that will take the last 4 digits of your student id and an [5]
operator as input. The program will determine the last digit of your student id
and perform an operation on that digit three times, using the switch case
statements.

Sample Input Sample Output

1145 * 5 * 5 * 5 = 125

1123 + 3+3+3=9

1128 - 8-8–8=-8

1122 ? The input is invalid

You might also like