0% found this document useful (0 votes)
29 views5 pages

C Programs for Basic Calculations

hi

Uploaded by

bejjiprasad2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

C Programs for Basic Calculations

hi

Uploaded by

bejjiprasad2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Write a C program to calculate the total cost of purchasing several items,


including a discount if the total cost exceeds a certain threshold.
Note: A shop offers a discount if the total cost of purchased items exceeds
$100. Calculate the total cost after applying the discount (if applicable).
The discount is 10%.
Template.c
#include <stdio.h>

/* Include any headers here */

int main()
{
/* Put your declarations here */
float price1, price2, price3, total_cost, discount, final_cost;

/* --- Start your solution here --- */

/* --- End of the solution --- */


return 0;
}

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>

/* Include any headers here */

int main()
{
/* Put your declarations here */
int num1, num2, num3;

/* --- Start your solution here --- */

/* --- End of the solution --- */


return 0;
}

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>

/* Include any headers here */

int main()
{
/* Put your declarations here */
int year;

/* --- Start your solution here --- */

/* --- End of the solution --- */


return 0;
}

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>

/* Include any headers here */

int main()
{
/* Put your declarations here */
int a, b;

/* --- Start your solution here --- */

/* --- End of the solution --- */


return 0;
}

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>

/* Include any headers here */

int main()
{
/* Put your declarations here */
float subject1, subject2, subject3;

/* --- Start your solution here --- */

/* --- End of the solution --- */


return 0;
}

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

You might also like