CS101 Programming For Problem Solving (Mid - SP23)
CS101 Programming For Problem Solving (Mid - SP23)
INSTRUCTIONS:
1. The question paper contains 5 questions each of 5 marks and total 25 marks.
2. Attempt all questions.
3. The missing data, if any, may be assumed suitably.
4. Tables/Data handbook/Graph paper etc., if applicable, will be supplied to the candidates
-----------------------------------------------------------------------------------------------------------------------------
CO BL
Q.1(a) Compare Pseudocode with an algorithm for the Program Factorial of a Number. [2] CO2 BL4
Q.1(b) Write a C program to convert a decimal number into an equivalent binary number [3] CO1, BL3
using bitwise operators. C04
Q.2(a) Amicable numbers are found in pairs. A given pair of numbers is Amicable if the [2] CO1, BL3,
sum of the proper divisors (not including itself) of one number is equal to the other CO4 BL4
number and vice–versa.
For example, 220 &284 are amicable numbers.
First, we find the proper divisors of 220:
220:1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110
1+ 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284
Now, 284: 1, 2, 4, 71, 142
1 + 2 + 4 + 71 + 142 = 220
(II) Given a= 10, b=5 and c=6, evaluate the following logical expression:
d= ((a < b) & & (b > c)) | | (a > c)
Q.3(a) How many lines of output does the following ‘C’ code produce? [2] CO3 BL4
#include<stdio.h>
float i=2.0;
float j=1.0;
float sum = 0.0;
main ()
{
while (i/j > 0.001)
{
j+=j;
sum=sum+(i/j);
printf("%f\n", sum);
}
}
Q.3(b) Write a program in C to check whether a number can be expressed as the sum of [3] CO1, BL3,
two prime. CO4 BL4
Test Data: CO5
Input a positive integer: 16
Expected Output:
16=1+15 // both are not prime
16=2+14 //2 is prime but 14 is not
16 = 3 + 13 // both are prime (ANS.)
16=4+12 //both are not prime
16 = 5 + 11 // both are prime (ANS.)
16=6+10 // both are not prime
16=7+9 // 7 is prime but 9 is not
PTO
Q.4(a) Write a C program to implement password registration, that accepts a string as [2] CO4, BL3,
password if it is at least 8 characters in length, has at least one capital letter, small CO5 BL4,
letter, digit, and a special character. BL6
Q.4(b) Write a C program to search a name in a list using binary search techniques. [3] CO5 BL3,
BL4
Q.5(a) Find the total number of swaps that take place when sorting the following set of [2] CO4 BL4
numbers using bubble sort. Show the passes in individual steps.
Location 1 2 3 4 5 6
Elements 33 77 46 99 12 56
For example, if the positions of 33 and 12 are interchanged, it is called one swap.
::::::30/05/2023::::::M