Coding Assignment: CSE 1110: Introduction To Computer Systems Basic Problems
Coding Assignment: CSE 1110: Introduction To Computer Systems Basic Problems
Coding Assignment
Basic problems
Introduction to printf function
1. Write a C program that will print “Hello World!”
Sample input Sample output
Hello World!
2. Write a C program that will print the lines given in the sample output:
Sample input Sample output
Hello World!
Welcome to C programming.
This is going to be fun!
2. Write a C program where you will declare two integer variables, initialize them by values
of your choice, and perform the basic arithmetic operations on them. The basic arithmetic
operations are addition (+), subtraction (-), multiplication (*), division (/) and remainder
(%).
Sample input Sample output
18 + 7 = 25
18 – 7 = 11
18 * 7 = 126
18 / 7 = 2
18 % 7 = 4
3. Write a C program where you will declare two floating point variables, initialize them by
values of your choice, and perform the basic arithmetic operations on them. Note that the
remainder operation is invalid for floating point numbers.
Sample input Sample output
95.401 + 22.622 = 118.023
95.401 – 22.622 = 72.779
95.401 * 22.622 = 2158.161422
95.401 / 22.622 = 4.217178
4. Write a C program where you will declare four integer variables (say a, b, c and d),
initialize them by values of your choice, and calculate a * b + (a – c) / d + b.
Sample input Sample output
21 * 15 + (21 – 34) / 6 + 15 = 327
5. Write a C program where you will declare four floating point variables (say a, b, c and d),
initialize them by values of your choice, and calculate (a + b – c) * d – a / d.
Sample input Sample output
(2.3 + 5.8 – 1.1) * 3.5 – 2.3 / 3.5 =
23.842857
2. Write a C program where you will declare two integer variables, input them using scanf,
and perform the basic arithmetic operations on them.
Sample input Sample output
18 7 18 + 7 = 25
18 – 7 = 11
18 * 7 = 126
18 / 7 = 2
18 % 7 = 4
3. Write a C program where you will declare two floating point variables, input them using
scanf, and perform the basic arithmetic operations on them.
Sample input Sample output
95.401 22.622 95.401 + 22.622 = 118.023
95.401 – 22.622 = 72.779
95.401 * 22.622 = 2158.161422
95.401 / 22.622 = 4.217178
4. Write a C program where you will declare four integer variables (say a, b, c and d), input
them using scanf, and calculate a * b + (a – c) / d + b.
Sample input Sample output
21 15 34 6 21 * 15 + (21 – 34) / 6 + 15 = 327
5. Write a C program where you will declare four floating point variables (say a, b, c and d),
input them using scanf, and calculate (a + b – c) * d – a / d.
Sample input Sample output
2.3 5.8 1.1 3.5 (2.3 + 5.8 – 1.1) * 3.5 – 2.3 / 3.5 =
23.842857
6. Write a C program which will calculate the area of a circle, given its radius. (Assume that
pi = 3.14159)
Sample input Sample output
5 Area = 78.53975
7. Write a C program which will calculate the terminal velocity of a moving body by using
the following equation:
v=u+at
You have to take as input u, a and t in order. Can you figure out the data types for all the
variables?
Sample input Sample output
5 6 12 v = 77
8. Write a C program which will calculate the displacement of a moving body by using the
following equation:
1
s=ut+ a t 2
2
You have to take as input u, a and t in order. Have you faced any problem regarding the
output?
Sample input Sample output
5 6 12 s = 492
9. Write a C program which will take as input the height of an object in centimeters, and
represent it in meter-centimeter format.
Sample input Sample output
157 1 meter 57 centimeter
2309 23 meter 9 centimeter
10. Write a C program which will take as input the height of an object in inches, and represent
it in feet-inch format.
Sample input Sample output
57 4 feet 9 inch
79 6 feet 7 inch
11. Write a C program which will take as input a time interval in seconds, and represent it in
hour-minute-second format.
Sample input Sample output
3824 1 hour 3 minute 44 second
525 0 hour 8 minute 45 second
12. Suppose that in a country, there are notes of 1, 5, 10, 50, 100 and 500 units of currencies.
Write a C program which will take as input the amount of money to give, and find out the
number of each note to provide this amount of money so that a minimal number of notes
are given in total.
Sample input Sample output
1627 3 note(s) of 500
1 note(s) of 100
0 note(s) of 50
2 note(s) of 10
1 note(s) of 5
2 note(s) of 1
789 1 note(s) of 500
2 note(s) of 100
1 note(s) of 50
3 note(s) of 10
1 note(s) of 5
4 note(s) of 1
If-else Statement
1.
Program that will decide whether a number is positive or not.
3. Program that will take an integer of length one from the terminal and then display the digit in
English.
4. Program that will check whether a triangle is valid or not, when the three angles (angle value
should be such that, 0 < value < 180) of the triangle are entered through the keyboard.
[Hint: A triangle is valid if the sum of all the three angles is equal to 180 degrees.]
5. Program that will take two numbers X & Y as inputs and decide whether X is greater
than/less than/equal to Y.
Problem on Loop
1. Write a program (WAP) that will print following series upto N th terms.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …….
2. Write a program (WAP) that will print following series upto N th terms.
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 …….
3. Write a program (WAP) that will run and show keyboard inputs until the user types an ’A’ at
the keyboard.
Sample input Sample output
X Input 1: X
1 Input 2: 1
a Input 3: a
A
4. Write a program (WAP) that will take two numbers X and Y as inputs. Then it will print the
square of X and increment (if X<Y) or decrement (if X>Y) X by 1, until X reaches Y. If and when X
is equal to Y, the program prints “Reached!”