Write a program that allows user inputting a simple expression containing one of four
operators +, -, *, / then the result is printed out to the monitor. Input format: num1 operator
num2,
An example of user interface
Enter an expression (+ - * /): 4*5
Result: 20
Sample Analysis
Content Implementation
Nouns Expression, double num1, num2
format num1 operator num2 char op
double result
result
Verbs Begin
Accept num1, op, num2 scanf( “%lf%c%lf”, &num1, &op, &num2)
Calculate result switch (op)
Print out result { case ‘+’ : result = num1 + num2;
End print out result;
break;
case ‘-’ : result = num1 - num2;
print out result;
break;
case ‘*’ : result = num1 * num2;
print out result;
break;
case ‘/’ : if ( num2==0)
print out “Divide by 0
“
else
{ result = num1 / num2;
print out result;
}
break;
default: print out “Op is not
supported”
}
===
1. Present the algorithm and write program to calculate the area of a triangle with three sides
known (using Heron's formula)
Where:
p is the half-perimeter of the triangle
2. Present the algorithm and write program to find the Fibonacci sequence with n input from
the keyboard (not use recursion)
Input: 10
Output: 0 1 1 2 3 5 8 13 21 34
3. Present the algorithm and write program to check prime number
Input: 44
Output: not prime number
Input: 7
Output: prime number
4. Present the algorithm and write program to check palindrome number
Input: 329
Output: not palindrome number
5. Present the algorithm and write program to reverse a given number
Input : num = 12345
Output: 54321
Input : num = 876
Output: 678
6. Present the algorithm and write program to calculate the value of S where S = 1 + 1/2 + 1/3
+ … + 1/50.
7. Present the algorithm and write program to convert decimal number to binary
Input: 5
Output: 101
Input: 20
Output: 10100
8. Present the algorithm and write program to calculate the value of the following
expression
(x+y) * (x-y) * (y-z) / (x- y + z)
532
(5 + 3) * ( 5 – 3) * ( 3 -2) / (5 – 3 +2)
8 * 2 * 1/ 4
9. Present the algorithm and write program to convert number in characters
Input: 5
Output: five
Input: 203
Output: two zero three
10.
Yearly Personal Income Tax
Suppose that:
In Viet Nam, each people has to pay for his/her yearly personal income tax as the following
description:
Rules:
Tax-free income:
Personal pending amount (tiền nuôi bản thân) pa= 9 000 000$/month
Alimony (tiền cấp dưỡng) for each his/her dependent pd= 3 600 000$/month/dependent
With n dependents, Yearly tax-free income: tf = 12*(pa + n*pd)
Taxable income (thu nhập chịu thuế)
ti = income – tf
( If ti<=0 then income tax = 0)
Based on taxable income, the employee has to pay his/her income tax with levels pre-
defined in the following table:
Level Taxable Income Income tax
1 Less than or equal to 5.000.000 5%
2 From 5.000.001 to 10.000.000 10%
3 From 10.000.001 to 18.000.000 15%
4 Over 18.000.000 20%
Write a program which will compute income tax of a people using the following interface:
Case 1:
Your income of this year: 240000000
Number of dependent:4
Tax-free income: 280800000
Taxable income: 0
Income tax: 0
Case 1:
Your income of this year: 440000000
Number of dependent:4
Tax-free income: 280800000
Taxable income:: 159200000
Income tax: 30190000
11. Write a C program that will print out sum of integers inputted from the keyboard until the
value 0 is inputted.
12. Write a C program that will carry out some times: accept two integers, swap these values,
print them out to the monitor. The program will terminate when the value of 0 is inputted.
13. Write a C program that will:
- permit user inputting a string of characters. The input operation will terminate if the
ENTER key is stroked.
print out the number of vowels, number of consonants, and number of others to the monitor.
14. Write a C program that will print out the ASCII code table.
15. Write a C program that will accept two characters then print out ASCII code difference
between them and characters between them including code values in decimal, octal,
hexadecimal expansions in ascending order.
16. Write a C that will accept a positive integer n, n>=2 then print out primes between 2 and n.
17. Write a C program that will accept data of a day then print out whether they are valid or
not.
18. Write a C program that will accept a point and a circle having the center is (0,0) then print
out the relative position of this point with the circle.
19. Write a C program that will accept a positive integer then print out its factorial.
20. Write a C program that will print out the value at the nth position in Fibonacci sequence.
21. Write a C program that will accept a positive integer then print out whether it is an element
of the Fibonacci sequence or not.
22. Write a C program that will carry out some times. In each time, a nonnegative integer is
accepted then print out the sum of its decimal digits. The program will terminate when its value
of accepted number is negative.
23. Write a C program that will accept the integral part and fraction of a real number then print
out the this real number.
Example : 32 25 32.25
25 0.25 32+0.25= 32.25
Example -51 139 -51.139
139 0.139 -51- 0.139= -51.139
24. Write a C program that will accept two positive integers then print out their greatest
common divisor and least common multiple.
25. Write a C program that will accept a non-negative integer then print out its minimum and
maximum digits.
Example: n= 10293 Print out 9, 0
26. Quadratic equation
27. Calculate S(n) = ½ + ¼ + … + 1/2n
28. Calculate S(n) = 1 + 1/3 + 1/5 + … + 1/(2n + 1)
29. Calculate the product of all the “divisors” of the positive integer n
30. List all the “odd divisors” of the positive integer n