C Programming Practicals1 - Buea - 24
C Programming Practicals1 - Buea - 24
PRACTICAL/TUTORIAL SHEET
A. PRACTICING EXERCISES:
Practice the following C programming codes:
1. To display "hello world"
3. To get an integer number from the user and display it on the screen
4. To get an integer number from the user and check if it is positive or negative
5. To get an integer number from the user and check if it is odd or even
6. To get two integer numbers from the user and displays the sum and average
7. To get two real numbers from the user and displays the sum and average
8. To get two integer numbers from the user and check if one is bigger or both are equal
B. THINKING EXERCISES:
Write a C Program making use of strings, if statements, for loop, while loop, do while loop,
arrays, functions, pointers, files where necessary. Comment your work to make it explicit.
1. To prompt for three integer values from the keyboard and prints the highest of the numbers on the screen
using:
a) if statement
b) case statement
2. To display the sum and the average of the first 100 integer numbers on the screen using:
a) for loop
b) while loop
c) Do while loop
3. To convert from Decimal to Binary number system
4. To get an integer number and checks if it is odd or even. If odd, add 1, if even, add 2
5. To get an integer number and check if it is prime or not
6. To get an integer number and get the first and last digit then add them
7. To get an integer number and display the factors
8. To get two integer numbers and look for the LCM and HCF
9. To count number of digits in an integer
10.To check if a number is a Strong number or not. (a Strong number is a special number
whose sum of factorial of digits is equal to the original number. For example: 145 is
strong number. Since, 1! + 4! + 5! = 145)
11.To check if a number is an Armstrong number or not. (An Armstrong number is a n-digit
th 1
number that is equal to the sum of the n power of its digits. For example 6 = 6 = 6 ; 371
3 3 3
= 3 + 7 + 1 = 371)
12. To print Fibonacci series (Fibonacci series is a series of numbers where the current
number is the sum of previous two terms. For Example: 0, 1, 1, 2, 3, 5, 8, 13, 21, ... , (n-
1th + n-2th)
13. To check whether the number is Perfect number or not (Perfect number is a positive integer
which is equal to the sum of its proper positive divisors. For example: 6 is the first perfect number
Proper divisors of 6 are 1, 2, 3 Sum of its proper divisors = 1 + 2 + 3 = 6. Hence 6 is a perfect number)
Exercise 2
Design the algorithm of question 6 and implement it in the language of your choice using your computer.