CS-114 | Fundamentals of Programming Practice Problems
Problems (from Lectures and Quizzes)
Simple Problems
1. Find square/cube of a number
2. Find sum/difference/product/division of two/three numbers
3. Find average of two numbers
4. Find velocity from given distance and time
5. Find acceleration from given velocity and time
6. Calculate area of a rectangle ( area = base * height )
7. Calculate marks percentage ( marks percentage = marks obtained / total * 100 )
8. Calculate sales tax ( tax = amount * tax percentage / 100 )
9. Find ‘no. of minutes’ and ‘no. of seconds’ from given ‘no. of hours’
10. Find the value of F (centripetal force) for given values of mass ‘m’, velocity ‘v’ and radius
‘r’ (where F = mv2 / r)
11. Find the value of A such that A = (4x – 3y) / 2z
12. Find the value of distance ‘D’ for given values of ‘x’, ‘v’,‘t’, ‘a’
(where D = x + vt + 1/2at2)
13. Find the value of A such that A = (a - b)2 / 2c
14. Find the value of E (total energy) for given values of ‘m’, ‘v’, ‘g’, ‘h’
(where E = mv2 / 2 + mgh)
15. Find the value of A such that A = (a + b)2 – 2ab
Simple Decision Making (Simple Decision Rules)
16. Find absolute value of difference of two numbers
17. Find smaller/larger of two numbers
18. Find whether a numbers is negative or not
19. Find whether two numbers are equal or not
20. Multiply two numbers if their difference is greater than 0
21. Find whether the sum of two numbers is greater than 50
22. Find whether the sum of two numbers is greater than the third number
23. Divide a number by another if and only if the second number is not equal to 0
24. Determine whether a student is ‘passed’ or ‘failed’ from his marks
25. Divide two numbers if their difference is greater than 10, otherwise multiply them.
26. Determine whether the “average” of two numbers is negative or not.
27. Multiply two numbers if their sum is greater than 100, otherwise divide them.
28. Determine whether the “Product” of two numbers is negative or not.
29. Subtract two numbers if their sum is greater than 100, otherwise divide them.
30. Determine whether the “average” of three numbers is negative or not.
31. Find sum of two numbers (If second number is equal to 0 add 5 to it)
1
CS-114 | Fundamentals of Programming Practice Problems
Simple Decision Making (Composite Decision Rules)
32. Divide a number by another if second number is between 0 and 10
33. Add two numbers if either of them is 0
34. Determine status of a student from marks of two of his subjects for following:
a. If marks for both the subjects are greater than 40, he’s passed
b. If marks for either of the subjects are greater than 40, he’s passed
35. Determine status of a student from marks of two of this subjects and his GPA
If either the marks for both of the subjects are greater than 40 or
GPA is greater than 2, he’s considered passed
36. Determine whether a student has got ‘Grade A’ from his total marks and his GPA
If marks are greater than 80 and less than 90 OR GPA is greater than
3.7 and less than 3.8, he’ll be graded ‘A’
37. Determine whether a car is of mid-size type or not from its price (in millions) and engine
capacity (in cc)
If price is between 1 million and 2 million or if engine capacity is
between 1000 and 1500, a car is considered to be a mid-size car
38. Determine whether a cell-phone is a “smart phone” or not, from its price and display
width
A cell-phone is considered a “smart-phone”, if its price is from
20,000 to 30,000 or its display width is from 5 to 8 inches
39. Determine whether an employee is Manager or not, from given salary and pay grade.
An employee is considered a “Manager”, if his salary is between
50,000 to 80,000 or his pay grade is from 19 to 22
40. Determine whether an employee is an Executive or not, from given salary and pay
grade.
An employee is considered an “Executive”, if his salary is between
80,000 and 100,000 or his pay grade is from 20 to 22
Complex Decision Making
41. For two numbers, do the following
If second number is greater than 0, divide them
If second number is less than 0, multiply them
If second number is equal to 0, add them
42. For given roll number of a student, display his name
Assume that there are only three students
43. Display the name of a city against the given city code (do it for 4-5 cities)
44. Find smallest/largest of three/four numbers
45. For given day number of the week, display the corresponding day
46. Find season from given month number
2
CS-114 | Fundamentals of Programming Practice Problems
47. Write a program to check if a year is leap year or not.
If a year is divisible by 4 then it is leap year but if the year is century year like 2000,
1900, 2100 then it must be divisible by 400.
48. Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following
rules print their place of service.
if employee is female, then she will work only in urban areas.
if employee is a male and age is in between 20 to 40 then he may work in anywhere
if employee is male and age is in between 40 t0 60 then he will work in urban areas only.
And any other input of age should print "ERROR".
49. A 4 digit number is entered through keyboard. Write a program to print a new number
with digits reversed as of orignal one. E.g.-
INPUT : 1234 OUTPUT : 4321
INPUT : 5982 OUTPUT : 2895
50.
51. Find grade from given total marks of a student
Marks Range Grade
90 or above A+
85 to 89 A
75 to 84 B
65 to 74 C
50 to 64 D
Below 50 F
52. Perform the appropriate operation on given two numbers depending upon the given operation type
Operation Type Description
1 Addition
2 Subtraction
3 Multiplication
4 Division
53. Find temperate in Celsius or Fahrenheit from given temperature and conversion type
Conversion Type Description Formula
1 Celsius 32 + (temperature * 1.8)
2 Fahrenheit (temperature - 32) / 1.8
3 Kelvin 273.15 + temperature
4 Rankie Temperature * 5/9
54. Find weight in appropriate unit from given weight in kilograms and conversion type
Conversion Type Description Formula
1 Gram 1000 * weight
2 Milligram 10000 * weight
3
CS-114 | Fundamentals of Programming Practice Problems
3 Grains 1000 * 15.43 * weight
4 Pounds 2.20 * weight
Repetitions (Without Decision Making)
55. Find/Display first n integers
56. Find sum of first n integers
57. Find factorial of a number
58. Find xy
59. Find sum of first n even numbers
60. Find sum of first n odd numbers
61. Find/Display first n even numbers
62. Find/Display first n odd numbers
63. Find sum of numbers between any two integers
64. Display multiplication table of a number up to n
65. Find sum of first n integers numbers starting from 26
66. Find/Display first n numbers of the following series
1 2 4 7 11 16 22 ………
67. Find/Display first n numbers of “Fibonacci (fee’ bo’ naachi) series”
68. Find the sum of reciprocals of first n
a. integers i.e., 1 + 1/2 + 1/3 +……+ 1/n
b. odd numbers i.e., 1 + 1/3 + 1/5 +……+ 1/n
c. even numbers i.e., 1/2 + 1/4 + 1/8 +……+ 1/n
69. Display the first n numbers of the following series:
a. 1/4 1/16 1/64 1/256 ………
b. 1/3 1/9 1/27 1/81 ………
c. 1/5 1/25 1/125 1/625 ………
Repetitions (With Decision Making)
70. Find even and odd numbers from first n integers
71. Find all numbers which are divisible by a number from first n integers
72. Find all odd numbers which are divisible by 3 from first n integers
73. Find sum of even numbers between any two integers
74. Find sum of odd numbers between any two integers
75. Find how many even and odd numbers are there between any two integers
76. Display multiplication table of a number only if the number is greater than 0
77. Find first power of a number which is greater than or equal to another number
78. Find whether a number is prime or composite
4
CS-114 | Fundamentals of Programming Practice Problems
79. Find first divisor of a number which is greater than 5
80. Between any two integers, find all numbers which are divisible by a number, only if the
given number is not equal to zero
81. Between any two integers, find all numbers which are divisible by 5 or 10
82. From first n integers, find all numbers which are divisible by 2 and its cube.
83. From first n integers, find all numbers which are divisible by a number and its square,
only if the given number is not equal to 0
84. From first n integers, find all numbers which are divisible by a number and its cube, only
if the given number is not equal to zero
85. Between any two integers, find the product of all numbers which are divisible by 3 or 7
Complex Repetitions (Repetitions within Repetitions)
86. For first n integers, find first power of every integer which is greater than a number
87. Find sum of ith powers of first n integers (where i can be any number)
88. Find prime numbers from first n integers
89. Find prime numbers between any two integers
90. Find kth powers of first n integers
where “k” is equal to the number itself i.e., 11 22 33 44 …… nn
91. Find first n prime numbers
92. Find odd prime numbers from first n integers (or between any two integers)
93. Find even prime numbers from first n integers (or between any two integers)
94. Find sum of factorials of first n integers (Hint: Factorial of a number = 1 × 2 × …× num)
95. Display multiplication tables of first n integers
Repeating the whole solution (as required by the User)
96. Find square of a number
97. Find sum of two numbers
98. Find whether a number is negative or positive
99. Find whether a number is prime or not