Lab Mid Exam (CS-201)
Lab Mid Exam (CS-201)
Lab Mid Exam (CS-201)
Note: Kindly return the question paper along with answer sheet
Sr. Marks
#
Write a function named "summation" that takes two integer arguments, call them "from" and
"to", and returns as its value the sum of all the integers between from and to inclusive.
Have the function KaprekarsConstant(num) take the num parameter being passed which will
be a 4-digit number with at least two distinct digits. Your program should perform the following
routine on the number. Arrange the digits in descending order and in ascending order and
subtract the smaller number from the bigger number. Then repeat the previous step. Performing
this routine will always cause you to reach a fixed number: 6174. Then performing the
routine on 6174 will always give you 6174 (7641 - 1467 = 6174). Your program should return
the number of times this routine must be performed until 6174 is reached. For example: if num
is 3524 your program should return 3 because of the following steps: (1) 5432 - 2345 =
3087, (2) 8730 - 0378 = 8352, (3) 8532 - 2358 = 6174.
Sample Run 1: Sample Run 2:
2 20
Input: 2111 Input: 9831
Output: 5 Output: 7
Constraints:
Page 1 of 2
University of Chakwal
Write a program to calculate the salary as per the following table.
3 10
Page 2 of 2