0% found this document useful (0 votes)
59 views2 pages

Lab Mid Exam (CS-201)

The document is a midterm exam paper for a Programming Fundamentals Lab course. It contains 3 programming problems worth various marks: 1) Write a function to calculate the summation of integers between two numbers (5 marks). 2) Write a function to calculate the number of iterations required for a 4-digit number to reach the Kaprekars constant of 6174 through a routine (20 marks). 3) Write a program to calculate salary based on a table (10 marks). The total marks for the exam are 35. The paper provides examples and constraints for each problem.

Uploaded by

Danish Irfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views2 pages

Lab Mid Exam (CS-201)

The document is a midterm exam paper for a Programming Fundamentals Lab course. It contains 3 programming problems worth various marks: 1) Write a function to calculate the summation of integers between two numbers (5 marks). 2) Write a function to calculate the number of iterations required for a 4-digit number to reach the Kaprekars constant of 6174 through a routine (20 marks). 3) Write a program to calculate salary based on a table (10 marks). The total marks for the exam are 35. The paper provides examples and constraints for each problem.

Uploaded by

Danish Irfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy