You are on page 1of 2

PDS LAB SECTION 1

ASSIGNMENT 03
CONDITIONALS AND LOOPS
(DO NOT USE ARRAYS OR USER-DEFINED FUNCTIONS)
JANUARY 24, 2024
Time: 2 Hours 30 minutes, Marks: 75 + 15 [Bonus] = 90
--------------------------------------------------------------------------------------------------------------
Write a C program that does the following:
a) Read a positive integer A and print it. Find the number of digits of A and print it.
(For example: 4536 had 4 digits)

b) Find and Print the sum of its even-valued digits of A. (For 4536, answer is 10)

c) Find and Print the largest and smallest valued digits in A. (For 4536, the answers
are 6 and 3)

d) Find and Print the next largest (which is not the same as the largest) and the next
smallest (which is not the same as the smallest) digits in A. In case the next largest
or next smallest does not exist, print the response suitably. (For 4536 the answers
are 5 and 4)

e) Read three positive integers and print them. Find out the HCF (highest common
factor) and LCM (Lowest Common Multiple) of these numbers and print them. (For
example 12, 32 and 64 have HCF as 4 and LCM as 192)

f) Then Find the next highest HCF and next lowest LCM of these integers and print
them. In case the next highest or next lowest does not exist, print a response
suitably. (For 12, 32, 64 next HCF is 2 and next LCM is 384)

g) Read two positive integers m and n such n > m. Check if n is prime and print the
result suitably.

h) Now find all prime numbers between m and n but not equal to m or n and print
them. If there are no such prime numbers, indicate the same suitably.
i) Next, read a digit D and Find and Print the smallest non-prime number larger than
n but not having the digit D. (For example, if n = 10 and D = 2, answer is 14)

j) Read a positive integer n and read n positive integers. Find the largest and next
largest digit that is common to all the integers read. If there is no such next largest
digit, print a response suitably. (For example if n =4 and numbers are 2745, 52478,
127, 56927, largest common integer is 7 and second largest common integer is 2).

k) [BONUS PROBLEM] Read an integer K and an integer L First find and print
whether there is any combination of digits of K whose sum is L. Then Among these
combinations who sum is L, find out that combination with the smallest number of
digits. (Assume that K has at most 5 digits). [This part contains an additional 15
marks]

Write the C Program above. Save the file as A03_<Roll Number>.c (example
A03_23AG10002.c). Build, Run and test it for different test inputs. Then upload the .c
file for the Assignment. (Remember to write the header file in your submission as
already explained. Format your C program for readability, stating comments explaining
the code.). Do not use arrays or user-defined functions. You may include and use only
stdio.h and math.h and no other library.

You might also like