ITP Exp9
ITP Exp9
QUESTIONS
1) Write a C program to decode a 4-digit password (as an example 2785). The most
significant digit (MSD) of this password is 2 and the least significant digit of this password is 5.
Your program must perform the following steps.
i) In the main function generate and print a 4-digit password using the rand function. Then call
the function separate void separate (int password);
ii) The separate function must separate the digits of the password one-by-one starting from the
MSD (i.e 2 first, then 7, then 8 and finally 5).
iii) For each digit of the password separate function calls the function decode int decode (int
digit)
iv) Decode function must guess the digit and returns the guess to the separate function. The
separate function must print the guessed digit of the password.
An example output of the program could be as follows
2) There are iterative algorithms to find real roots of nonlinear equations. In this question,
you need to implement one whose formula given below in C programming language.
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 −
𝑓′(𝑥𝑛 )
where 𝑓′(𝑥𝑛 ) is derivative of 𝑓(𝑥𝑛 ) function. In this question, you will find root of 𝑓(𝑥) =
3𝑥 2 − cos 𝑥, whose derivative function 𝑓′(𝑥) = 6𝑥 + sin 𝑥.
E-mail : [email protected]
Introduction To Programming Laboratory, Fall 2022
3) In number theory, a perfect number is a positive integer that is equal to the sum of its
proper positive divisors, that is, the sum of its positive divisors excluding the number itself.
Example: The first perfect number is 6. Its proper divisors are 1, 2, and 3, and 1 + 2 + 3 = 6.
The next perfect number is 28 = 1 + 2 + 4 + 7 + 14.
Write a C program to check whether the generated 10 number is a perfect number or not.
i) In the main function enter the shifting and scaling factors from the keyboard for the range of
the random numbers. Then, call the function checkPerfect 10 times for the generated 10
random numbers (Enter 3 as shifting value, 8 as scaling factor).
ii) The checkPerfect function checks whether a number is perfect or not. The checkPerfect
function returns 1 if the number is perfect, otherwise 0. int checkPerfect(int num);
E-mail : [email protected]