Professional Documents
Culture Documents
Faculty of Engineering
B.Sc. Eng. (Hons) in Engineering– Year 1 Semester 2
Laboratory Experiment 02
Following sample code prints, numbers in a range in the ascending order. The user can define the
minimum and the maximum limits of the range.
#include <stdio.h>
void main () {
printf("\n");
}
printf("\n");
}
Complete all the tasks given in the sheet and demonstrate it to an instructor. You should
Page 1 of 3
print all the results in the same console window. Refer Fig. 01, you may develop your own
code to obtain the same result.
Fig. 01
Task 01
Compile the code given above and observe the output. Give different input values and
understand the code.
Task 02
Divide all the generating numbers by 3 (three). Obtain the remainder of each.
Display your results in two different columns.
Task 03
Hint: even numbers can be divided by 2 and the remaining value will be zero whilst even
numbers won’t.
You may use the example code given below.
#include<stdio.h>
Page 2 of 3
void main () {
int a,b;
// example of ternary operator
b = 5;
a = 10;
(a == b) ? printf("a and b are equal"): printf( "a and b are
not equal");
}
Page 3 of 3