Lab Mid Exam (CS-201)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

University of Chakwal Reg # 20-CS____

Mid Semester Exam Fall 2020 Date: 06-02-2021


1st Semester 2K20-CS Time Allowed: 1:00 hour
Course: Programming Fundamentals Lab Maximum Marks: 35

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.

Thus, for example,


1 summation (4,7) //will print 22 because 4+5+6+7 = 22 5

summation (-3,1) //will print -5 because (-3)+(-2)+(-1)+0+1 = -5

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:

 Do not use Array and any special function

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

You might also like