Week 1 Programming Questions
Note: Try to solve these questions on your own before checking the solutions.
Question 1
Write a program that takes two integers as input from the user and performs the following operations:
- Addition
- Subtraction
- Multiplication
- Division
- Modulus
The program should then print the results of each operation in a formatted manner.
Note: The solution does not handle division by zero as conditional statements have not been covered yet.
Example:
Enter first integer: 10
Enter second integer: 3
Addition: 10 + 3 = 13
Subtraction: 10 - 3 = 7
Multiplication: 10 * 3 = 30
Division: 10 / 3 = 3
Modulus: 10 % 3 = 1
Question 2
Write a program that takes a character input from the user, an integer input, and a float input. The program should then print the ASCII value of the character, the square of the integer, and the cube of the float in a formatted manner.
Example:
Enter a character: A
Enter an integer: 4
Enter a float: 2.5
The ASCII value of 'A' is 65
The square of 4 is 16
The cube of 2.50 is 15.62
Question 3
Write a program that reads a 4-digit integer and prints the decimal value for each digit.
Example:
please enter number of 4 digits
5678
5678=5000+600+70+8
Question 4
Write a program that reads a date (year, month, and day) and calculates the total number of days from year 0 up to that date.
Note: Assume a year has 360 days and a month has 30 days.
Example:
Enter the year: 2023
Enter the month (1-12): 1
Enter the day (1-31): 25
Total number of days from year 0 is: 728305
Question 5
Write a program that takes three integers as input, calculates their average, and prints the result as a float with 2 decimal places.
Example:
Enter the first integer: 10
Enter the second integer: 20
Enter the third integer: 34
The average is: 21.33
Question 6
Write a program that takes an integer representing an amount of money in dollars input from the user and breaks it down into the minimum number of bills of $100, $20, $5, and $1.
Example:
Enter amount in dollars: 288
$100 bills: 2
$20 bills: 4
$5 bills: 1
$1 bills: 3
Question 7
Write a program that takes a positive floating-point number input from the user and rounds it to the nearest integer.
Note: You are not allowed to use any functions from
<math.h>(likeround(),floor(),ceil()) or conditional statements.
Example:
Enter a floating-point number: 5.5
Rounded value: 6