0% found this document useful (0 votes)
56 views

01 Basic

This document provides 12 problems for practicing C programming concepts like printf, variables, arithmetic operations, scanf, math functions, and currency conversions. The problems cover basics like printing text, declaring and initializing variables, and arithmetic calculations. More advanced problems involve user input, math operations, conversions between units like centimeters to meters, and calculating change using different currency denominations. The goal is to write C code that matches the provided sample input and output for each problem.

Uploaded by

sahmed2330154
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

01 Basic

This document provides 12 problems for practicing C programming concepts like printf, variables, arithmetic operations, scanf, math functions, and currency conversions. The problems cover basics like printing text, declaring and initializing variables, and arithmetic calculations. More advanced problems involve user input, math operations, conversions between units like centimeters to meters, and calculating change using different currency denominations. The goal is to write C code that matches the provided sample input and output for each problem.

Uploaded by

sahmed2330154
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSE 1110: Introduction to Computer Systems

Problem Set for C programming


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!
3. Write a C program that will print a short composition of your choice.
Introduction to variables and arithmetic operations
1. Write a C program where you will declare an integer, a floating point and a character
variable, initialize them by values of your choice, and print these values.
Sample input Sample output
Integer value = 17
Floating point value = 3.508
Character value = W
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
The scanf function and uses of arithmetic oprators
1. Write a C program where you will declare an integer and a floating point variable, input
them using scanf, and print these values.
Sample input Sample output
17 3.508 Integer value = 17
Floating point value = 3.508
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:

You have to take as input , and 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:

You have to take as input , and 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
The math.h header
1. Write a C program that will take as input a floating-point number, and print the floor and
the ceiling of that number.
Sample input Sample output
5.7 Floor = 5
Ceiling = 6
-5.7 Floor = -6
Ceiling = -5

2. Write a C program that will take as input two floating point numbers and , and print
the value of .
Sample input Sample output
34 81.00
5.2 1.5 11.85

3. Write a C program that will take as input an angle in radian, and calculate the sine, the
cosine and the tangent of the angle.
Sample input Sample output
1 Sine = 0.84
Cosine = 0.54
Tangent = 1.55
0.524 Sine = 0.50
Cosine = 0.86
Tangent = 0.57

4. Write a C program that will calculate the terminal velocity of a moving body by using the
following equation:

You have to take as input the values of , and in order, and output the value of (not
).
Sample input Sample output
5 6 20 v = 16.27
5. Write a C program that will solve the following quadratic equation:

You have to take as input the values of , and in order. The solutions can be
calculated by the following equation:

Sample input Sample output


156 x1 = -3.00
x2 = -2.00
1 -4 4 x1 = 2.00
x2 = 2.00

You might also like