Lab 3 Solution
Lab 3 Solution
Lab 3
Objective:
1. Precedence
2. Increment and Decrement
3. Casting
4. Knowing more about float numbers
5. Swapping two variables
6. Using % to extract digits from a number
7. Introduction to if conditions
1. Write a program that reads three integers and prints the average of the integers. (Using
different types of casting)
2. Write a C program that reads two integers in variables a and b, exchanges them and prints
the values of a and b after exchanging:
3. Write a program that reads one five-digit number, then separates the number into its
individual digits, and prints the digits separated from one another by two spaces each.
[Hint: Use combinations of integer division and the remainder operation.]
For Example if the user types in 42139, the program should print 4 2 1 3 9
[Hint: Use 5 variables to split the integer, i.e. variable for each digit]
4. Write a program that reads an integer and determines and prints whether it is odd or even.
[Hint: Use the remainder operator. An even number is a multiple of two.]
Assignment
1. Write a program that reads in three integers and then determines and prints the
largest and the smallest integers in the group.
Sample Run:
Input three integers: 4 5 3
5 is the largest, 3 is the Smallest
Another solution