ICS - Papers
ICS - Papers
ICS - Papers
INSTRUCTIONS
1. Carefully write your name, section, seat no., and enrollment number.
2. Read carefully question before attempting.
3. Attempt any FOUR (4). All carries equal marks.
Q1: Write a program that takes an input form user and check whether a given input is palindrome or
not?
Hint: A palindrome is sequence of characters or numbers represents a word or phrase that if reads either
forwards or backwards as give the same meaning such as MADAM, NURSES RUN, or 10101.
Q2. Write a program that takes two inputs from the user and find the sum of all number in given range
using lambda
For example
If given inputs are 11 and 15, it should calculate 11+12+13+14+15 and output as
the sum of given rage is 65
Q3: Write a program that uses the given two list and create a new list that contains even numbers from
the first list and odd numbers from the second list. Then, print the all the members of new list.
numList1 = [17, 12, 25, 3, 36, 49, 28]
numList2 = [19, 40, 30, 15, 60, 75, 50]
Expected output
12, 36, 28, 19, 15, 75
Q4: Write a program that takes an input list of random numbers and calculate the frequency of even,
odd and prime number in the given list.
Expected output:
If given list is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Total Even numbers: 7
Total Odd numbers: 8
Total prime numbers: 6
Q5: Write a program that draw the triangle of alphabets as shown below
A
B C
D E F
G H I J
K L M N O
Department of Computer Science 301 – Introduction to Computer Science
University of Karachi Examination Dated:
BS Program Max. Time: 02:00 Hours Max Marks. 30
INSTRUCTIONS
1. Carefully write your name, section, seat no., and enrollment number.
2. Read carefully question before attempting.
3. Attempt any FOUR (4). All carries equal marks.
Q1: Write a program that takes an input from user and check whether a given number is Armstrong or
not.
Hint: Armstrong Number, is an integer which is equal to the sum of cube of its digits.
For example the given number is 370. The cube of given number digits are
3 x 3 x 3 = 27, 7 x 7 x 7 = 343 , and 0 x 0 x 0 = 0.
Now the sum of the cube of each digit is 27 + 343 + 0 = 370. It means 370 is an Armstrong number.
Q2: Write a program that takes an input from the user and check whether the given number is the
Fibonacci series number or not using user-defined function.
Hint: The Fibonacci Series, starts with 0 and 1, and it grows by adding previous two terms of series.
For example, 0, 1, (by adding 0+1) 1, (by adding 1+1) 2, (by adding 2+1) 3.
Therefore, series is 0, 1, 1, 2, 3… and so one.
Q3: Write a Program that takes an input from user and shows the given number digits in reverse order
separated by space.
For example, If the given number is 36987, the output will be as 7 8 9 6 3
Q4: Write a program that takes an input from user and convert the given number into binary
For example, if the given number is 67, then the output will be 0100 0011
INSTRUCTIONS
1. Carefully write your name, section, seat no., and enrollment number.
2. Read carefully question before attempting.
3. Attempt any FOUR (4). All carries equal marks.
Q1: Write a program that takes an input form user and check whether a given input is palindrome or
not, using recursion technique?
Hint: A palindrome is sequence of characters or numbers represents a word or phrase that if reads either
forwards or backwards as give the same meaning such as MADAM, NURSES RUN, or 10101.
Q2: Write a program that takes an input from user and convert the given number into octal
For example, if the given number is 459, then the output will be 713
Q3: Write a program that takes an input from user and calculate the frequency of vowels in the given
input. Also, the frequency of each vowel character in the given sentence.
Hint: The alphabets A, E, I, O, and U are vowels characters.
Q4: Write a program that takes an input form user and check whether the given input is a perfect
number or not?
Hint: A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the
number itself.
For example, 6 is a positive number and its divisor is 1, 2, 3 and 6 itself. But we should not include 6 as by the
definition of perfect number. So, only compute the sum of its divisor excluding the number itself.
1+2+3 = 6 which is equal to number itself. It means 6 is a Perfect Number.
Q5: Write a program that draw the rewind button of alphabets as shown below
A
B B
C C C
D D D D
E E E
F F
G
Department of Computer Science 301 – Introduction to Computer Science
University of Karachi Examination Dated:
BS Program Max. Time: 02:00 Hours Max Marks. 30
INSTRUCTIONS
1. Carefully write your name, section, seat no., and enrollment number.
2. Read carefully question before attempting.
3. Attempt any FOUR (4). Each carries equal marks.
Q1: Write a program that takes five inputs (integer) from users and display the algebraic pyramid of
addition.
Hint: The algebraic pyramid of addition is composed of from the base values/item and grow by adding the two
adjacent (from left to right) values to produce the new layer of pyramid items. For example 1, 2, 3, 4, 5 are the 5
given inputs or base values. Sub up the two adjacent term to produce new terms 1+2, 2+3, 3+4, 4+5. This complete
one cycle of pyramid, each algebraic cycle produce new pyramid layer or level. Perform the same until there left
only 1 item.
Level 5 48
Level 4 20 28
Level 3 8 12 16
Level 2 3 5 7 9
Level 1 1 2 3 4 5
Q2: Write a program that takes two inputs from user and a range of number, then find all the number
that divisible by 1st number but not by 2nd given number. The resultant numbers should be printed in a
comma-separated sequence in a single line.
For Example: given inputs are 3 and 2, and range is 1 to 30.
The resultant sequence should be as 3, 9, 15, 21, 27
Q3: Write a program that takes an input from user and calculate the frequency of alphabets and digits
in a given input.
For example, user inputs “The help desk is staffed between 8.30 to 17.30 Monday to Friday.”
Alphabets: 44
Digits: 7
Q4: Write a program that takes a binary input from user and convert the given number into decimal
For example, if the given number is 0100 0011, then the output will be 67
Q5: Write a program that draw the diamond of alphabets, as shown below
A
B C
D E F
G H I J
K L M
N O
P