Вы находитесь на странице: 1из 5

CS-1114 | Programming Fundamentals

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. 5. 6. 7. 9.

Find velocity from given distance and time Find acceleration from given velocity and time Calculate area of a rectangle ( area = base * height ) Calculate marks percentage ( marks percentage = marks obtained / total * 100 ) Find no. of minutes and no. of seconds from given no. of hours r (where F = mv2 / r)

8. Calculate sales tax ( tax = amount * tax percentage / 100 )

10. Find the value of F (centripetal force) for given values of mass m, velocity v and radius 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)


Instructor: Nadia Mushtaq

All Rights Reserved to Department of Computer Science UOL

CS-1114 | Programming Fundamentals

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, hes passed b. If marks for either of the subjects are greater than 40, hes 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, hes 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, hell 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 47. Calculate base pay from given annual salary and pay type
Instructor: Nadia Mushtaq All Rights Reserved to Department of Computer Science UOL 2

CS-1114 | Programming Fundamentals

Practice Problems

Base pay = salary / Dividing Factor


Pay Type Description Dividing Factor

1 2 3

Weekly Bi-Monthly Monthly

52 24 12

48. Find grade from given total marks of a student


Marks Range Grade

90 or above 85 to 89 75 to 84 65 to 74 50 to 64 Below 50

A+ A B C D F

49. Perform the appropriate operation on given two numbers depending upon the given operation type
Operation Type Description

1 2 3 4

Addition Subtraction Multiplication Division

50. Find temperate in Celsius or Fahrenheit from given temperature and conversion type
Conversion Type Description Formula

1 2 3 4

Celsius Fahrenheit Kelvin Rankie

32 + (temperature * 1.8) (temperature - 32) / 1.8 273.15 + temperature Temperature * 5/9

51. Find weight in appropriate unit from given weight in kilograms and conversion type
Conversion Type Description Formula

1 2 3 4

Gram Milligram Grains Pounds

1000 * weight 10000 * weight 1000 * 15.43 * weight 2.20 * weight

Repetitions (Without Decision Making)


52. Find/Display first n integers

Instructor: Nadia Mushtaq All Rights Reserved to Department of Computer Science UOL 3

CS-1114 | Programming Fundamentals

Practice Problems

53. Find sum of first n integers 54. Find factorial of a number


55. Find xy

56. Find sum of first n even numbers 57. Find sum of first n odd numbers 58. Find/Display first n even numbers 59. Find/Display first n odd numbers 60. Find sum of numbers between any two integers 61. Display multiplication table of a number up to n
62. Find sum of first n integers numbers starting from 26

63. Find/Display first n numbers of the following series

11

16

22

64. Find/Display first n numbers of Fibonacci (fee bo naachi) series 65. 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 66. Display the first n numbers of the following series:
a. b. 1/4 1/3 1/16 1/9 1/25 1/64 1/27 1/125 1/256 1/81

c. 1/5

1/625

Repetitions (With Decision Making)


67. Find even and odd numbers from first n integers 68. Find all numbers which are divisible by a number from first n integers 69. Find all odd numbers which are divisible by 3 from first n integers 70. Find sum of even numbers between any two integers 71. Find sum of odd numbers between any two integers 72. Find how many even and odd numbers are there between any two integers 73. Display multiplication table of a number only if the number is greater than 0 74. Find first power of a number which is greater than or equal to another number 75. Find whether a number is prime or composite 76. Find first divisor of a number which is greater than 5 77. Between any two integers, find all numbers which are divisible by a number, only if the given number is not equal to zero 78. Between any two integers, find all numbers which are divisible by 5 or 10 79. From first n integers, find all numbers which are divisible by 2 and its cube.
Instructor: Nadia Mushtaq All Rights Reserved to Department of Computer Science UOL 4

CS-1114 | Programming Fundamentals

Practice Problems

80. 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 81. 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 82. Between any two integers, find the product of all numbers which are divisible by 3 or 7

Complex Repetitions (Repetitions within Repetitions)


83. For first n integers, find first power of every integer which is greater than a number 84. Find sum of ith powers of first n integers (where i can be any number)

85. Find prime numbers from first n integers 86. Find prime numbers between any two integers 87. Find kth powers of first n integers

where k is equal to the number itself i.e., 11


88. Find first n prime numbers

22

33

44 nn

89. Find odd prime numbers from first n integers (or between any two integers) 90. Find even prime numbers from first n integers (or between any two integers)

91. Find sum of factorials of first n integers (Hint: Factorial of a number = 1 2 num) 92. Display multiplication tables of first n integers

Repeating the whole solution (as required by the User)


93. Find square of a number 94. Find sum of two numbers 95. Find whether a number is negative or positive 96. Find whether a number is prime or not

Comprehensive Problems (Covering all afore-mentioned concepts)


97.Find even prime numbers from first n integers, if n is greater than 0

Your program should stop only when the user wants it to do so

http://owl.english.purdue.edu/owl/resource/601/01/

Instructor: Nadia Mushtaq All Rights Reserved to Department of Computer Science UOL 5

Вам также может понравиться