Assignment 3
Assignment 3
int main()
{
/* Put your declarations here */
float price1, price2, price3, total_cost, discount, final_cost;
Test Cases:
Input Output
30 Total Cost=150.00
50 Discount=15.00
70 Final Cost=135.00
10 Total Cost=80.00
30 Discount=0.00
40 Final Cost=80.00
90 Total Cost=960.00
150 Discount=96.00
720 Final Cost=864.00
200 Total Cost=750.00
420 Discount=75.00
130 Final Cost=675.00
2. Write a C program to determine the largest of three numbers entered by the
user.
Note: The user provides three numbers, and the program must determine and
print the largest of the three using relational operators.
Template.c
#include <stdio.h>
int main()
{
/* Put your declarations here */
int num1, num2, num3;
Test Cases:
Input Output
5 The largest number is: 9
9
2
55 The largest number is: 97
97
69
157 The largest number is: 555
555
96
23 The largest number is: 966
966
355
3. Write a C program to determine if a given year is a leap year.
Note: A year is a leap year if it is divisible by 4 but not by 100, unless it is
also divisible by 400. Use logical operators to check these conditions.
Template.c
#include <stdio.h>
int main()
{
/* Put your declarations here */
int year;
Test Cases:
Input Output
2014 2014 is not a leap year.
2024 2024 is a leap year.
2000 2000 is a leap year.
1997 1997 is not a leap year.
4. Write a C program to swap two numbers without using a temporary
variable.
Note: Use bitwise XOR (^) to swap two numbers without needing an
additional variable for temporary storage.
Template.c
#include <stdio.h>
int main()
{
/* Put your declarations here */
int a, b;
Test Cases:
Input Output
5 Before swapping: a = 5, b = 9
9 After swapping: a = 9, b = 5
295 Before swapping: a = 295, b = 365
365 After swapping: a = 365, b = 295
5. Write a C program to check if a student pass based on their average score
of three subjects.
Note: The program should calculate the average of three subject marks. If the
average score is greater than or equal to 40, the student passes; otherwise, they
fail. Also, the student should score at least 33 marks in each subject to pass.
Template.c
#include <stdio.h>
int main()
{
/* Put your declarations here */
float subject1, subject2, subject3;
Test Cases:
Input Output
56 The student fails.
24
36
78 The student passes.
38
65
96 The student fails.
45
12
54 The student passes.
45
36