0% found this document useful (0 votes)
4 views8 pages

Hang Phannat (TP3)

The document outlines several C programming problems, including determining if a number is positive or negative, categorizing numbers, finding the minimum of seven inputs, solving a quadratic equation, calculating tax based on salary and gender, and computing average scores to assign grades. Each problem includes sample inputs and expected outputs. The document serves as a guide for implementing these programming tasks.

Uploaded by

bunnetchan
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)
4 views8 pages

Hang Phannat (TP3)

The document outlines several C programming problems, including determining if a number is positive or negative, categorizing numbers, finding the minimum of seven inputs, solving a quadratic equation, calculating tax based on salary and gender, and computing average scores to assign grades. Each problem includes sample inputs and expected outputs. The document serves as a guide for implementing these programming tasks.

Uploaded by

bunnetchan
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
You are on page 1/ 8

TP3-Condition 1

Name: HANG Phannat

ID: e20230626

Problem1- Write a C program to get a number from a user. The program tells us whether this

input number is a positive or a negative number.

INPUT:

Enter a number: -100

OUTPUT:

-100 is a negative number

Code

Result:

Problem2- Write a C program to get a number from a user. The program tells us whether this

input number is either one of the following categories below: A) negative and odd numbers, B)

negative and even numbers, C) positive and odd numbers, and D) positive and even numbers.

INPUT:
Enter a number: 50

OUTPUT: It is in the category D because it is a positive number and it is also an even number.

Code

Result

Problem3- Write a C program to ask a user for 7 numbers (7 variables). Find the minimum

number and display on screen.

INPUT:

Enter number #1: 2

Enter number #2: 99

Enter number #3: 1

Enter number #4: 2


Enter number #5: 9

Enter number #6: -7

Enter number #7: 5

OUTPUT:

The minimum number is -7

Code:

Result :

Problem5- Write a C program to solve the quadratic equation. ax2 + bx + c= 0 .

Ask a user to input the coefficients a, b and c. The program calculates delta and find roots of the

equation. Display the result (roots of the equation) on screen.

INPUT:

Input a: 1
Input b: 4

Input c: 3

OUTPUT:

The delta value of this equation equals 4.

So this equation has two roots: 𝑥1 1 = −1 and 𝑥2 = −3

Remark: Make sure you verify the result from the program whether it is correct if we do it

manually by hand .

code:
Result:

Problem6- Write a C program to tell how much tax a person should pay based on his/her salary
and gender. The program ask a user for gender, name, and salary (US dollar). The tax is

computed according to the following rules:

-pay tax 10%, for male and his salary is more than 400 USD.

-pay tax 5%, for male and his salary is from 200 USD to 400 USD.

-pay tax 5%, for females and her salary is more than 500 USD.

-pay tax 3%, for females and her salary is from 250 USD to 500 USD.

-Otherwise, no need to pay tax.

INPUT:

Enter gender: F

What is your name ?: Sokha

Your salary in USD: 450

Output:

Hi Dara, based on your given information, the tax salary that

You need to pay: 13.5 USD.

Code:
Result:

Problem7- Write a C program to compute the average score of a student over 3 subjects Math,

English and Computer. Then tell which grade this student could get. The grading is based on

the following rules:

Average score: Grade

86 - 100 A

81 - 85 B

70 - 80 C

61 - 69 D

50 - 60 E

Below 50 F

INPUT:

Math score: 75.5

English score: 90

Language score: 85.5

Output:

Average score is: 83.66


This student gets grade B.

You might also like