Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
183 views

Coding Assignment: CSE 1110: Introduction To Computer Systems Basic Problems

The document provides 12 coding assignments to practice basic C programming concepts like printing output, using variables and data types, arithmetic operations, reading input with scanf, and conditional statements with if-else. The assignments start with very basic "Hello World" programs and printing output, then progress to more complex calculations, conversions between measurement units, and conditional logic. The goal is to help new programmers learn and practice common tasks in C like declaring variables, taking user input, performing math operations, and using conditional statements.

Uploaded by

selilipy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

Coding Assignment: CSE 1110: Introduction To Computer Systems Basic Problems

The document provides 12 coding assignments to practice basic C programming concepts like printing output, using variables and data types, arithmetic operations, reading input with scanf, and conditional statements with if-else. The assignments start with very basic "Hello World" programs and printing output, then progress to more complex calculations, conversions between measurement units, and conditional logic. The goal is to help new programmers learn and practice common tasks in C like declaring variables, taking user input, performing math operations, and using conditional statements.

Uploaded by

selilipy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

CSE 1110: Introduction to Computer Systems

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!

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:
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.

Sample input Sample output


100 Positive
-11.11 Negative
0 Positive

2. Program that will decide whether a number is even or odd.

Sample input Sample output


50 Even
-77 Odd
0 Even

3. Program that will take an integer of length one from the terminal and then display the digit in
English.

Sample input Sample output


9 nine
0 zero

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.]

Sample input Sample output


90 45 45 Yes
30 110 40 Yes
160 20 30 No
0 180 0 No

5. Program that will take two numbers X & Y as inputs and decide whether X is greater
than/less than/equal to Y.

Sample input (X,Y) Sample output


5 -10 5 is greater than -10
5 10 5 is less than 10
5 5 5 is equal to 5

6. Program that will decide whether a year is leap year or not.

Yes, if ( Year % 4 == 0 && year % 100 != 0 ) || ( Year % 400 ==0 )

Sample input Sample output


2000 Yes
2004 Yes
2014 No

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, …….

Sample input Sample output


2 1, 2
5 1, 2, 3, 4, 5
11 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

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 …….

Sample input Sample output


2 1, 3
5 1, 3, 5, 7, 9
11 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21

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!”

Sample input(X,Y) Sample output


10 5 100, 81, 64, 49, 36, Reached!
5 10 25, 36, 49, 64, 81, Reached!
10 10 Reached!

You might also like