Practice Questions
Practice Questions
1. A number is called an Armstrong number if the sum of the cubes of the digits of the number is
equal to the number. For example 153 = 1^3 + 5^3 + 3^3. Write a C program that asks the user to
enter a number and returns if it is Armstrong or not (use function).
2. Write a program in C that takes as input a set of numbers and calculates the mean, variance and
standard deviation. (variance is defined as Σ [(xi - x̅ )^2]/n - 1 , where xi =i th number in the set, x̅
is the mean and n=cardinality of the set ; standard deviation is the square root of variance).
3. Write a C program that calculates the HCF and LCM of two numbers.
4. Write a C program to display and find the sum of the series 1+11+111+....111 upto n. For eg. if
n=4, the series is : 1+11+111+1111. Take the value of 'n' as input from the user.
5. Write a C program that reads a positive integer n and then prints the following pattern
*********
_********
__*******
___******
____*****
_____****
______***
_______**
________*
where n is the number of lines.
6. Amicable numbers are found in pairs. A given pair of numbers is Amicable if the sum of the
proper divisors (not including itself) of one number is equal to the other 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
Write a C program to check that the input pair of numbers is amicable.
7. Write a C function for the following problem:
Given a positive integer n, print the binary representation of n.
Example:
If the array contains the following elements:
2, 3, 3, 5, 4, 8, 7, 11, 2
12. Take the price and quantity of items as an input. Write a C function to calculate the sum of the
prices. Write another C function to calculate the discount according to the following rules:
Example:
If the prices are as follows:
Item 1: 200
Item 2: 400
Item 3: 200
Item 4: 10
Item 5: 50
Example:
If the user chooses the option for cube, only one input is required i.e., the side. The volume is
then calculated and printed.
If the user chooses the option for cuboid, only three inputs are required i.e., length, breadth and
height. The volume is then calculated and printed.
14.Write a C program to check if a number has three consecutive 5s. If yes, print YES, else print NO.
Example:
Number: 1353554
Result: NO
Number: 345559
Result: YES
15. Write a C program to print the following pattern:
a) 1 b) 1
12 22
123 333
1234 4444
12 3 4 5 55555
16. Write a C program to accept 10 values in an integer array. Display the number of odd, even,
and negative numbers.
17. Write a C program to accept the basic salary of an employee from the user. Calculate the gross
salary on the following basis:
Basic HRA DA
18. Write a C function celsius() to convert degrees Fahrenheit to degrees Celsius. (The
conversion formula is °C = 5/9 * (°F - 32).) Use it to print a Fahrenheit-to-Centigrade table
for -40 to 220 degrees Fahrenheit, in increments of 10 degrees. (Remember that %f is the
printf format to use for printing floating-point numbers. Also, remember that the integer
expression 5/9 gives 0, so you won't want to use integer division.)
19. An Electricity board charges the following rates for use of electricity.
For the First 200 units : Rs 1 per unit
For the next 100 units : Rs 1.5 per unit
Beyond 300 units : Rs 2 Per unit.
Write a C Program to read no of unit consumed and print out total charge amount.
20. Write a C program, which will print two digit numbers whose sum of both digit is multiple of
seven.
e.g. 16,25,34......
21. Write a C program, That reads list of n integer and print sum of product of consecutive
numbers.
22. Write a C program that take 2 integer sets A[] and b[] as input and prints results of following
set operations:
i. A union B (Write function set_union())
ii. A intersection B (Write function set_intersection())
iii. A-B and B-A (Write function set_difference())
23. Write a C program to take a list of n elements from the user. Store it in an array. Reverse the
list.
24. Write a C program to check whether a given string is palindrome or not.
25. Write 2 different C functions to compute area and perimeter of a triangle whose sides a, b,
and c are given by user as inputs.
Your program should read the input data and print the output data via separate functions. The
prototypes are:
double read_input()
double print_value(double val)
26. Input size and values in two arrays A and B, of max size 100. Then, compute A[i]+B[i] and
store in array C. And compute A[i]*B[i] and store in array D.
27. Compute taxes for a given income with tax slab rates as follows...
calculation:
0-2500 of x:
0% of 2500 = 0
2500-5000 of x:
10% of 2500 = 250
5000-1000 of x:
20% of 200 = 40
output: 290
28. Input date, month and year from the user, and using switch case, display in worded format.
e.g.
input: d=16, m=7, y=1992
output: 16th July, 1992
29. Find out the ugly prime number
Desc: The given number is ugly prime number if it's prime factor
contains only among 2,3 or 5.
e.g. 20= 2*2*5 is ugly prime number
14=2*7 is not a ugly prime number
So write a C function which takes values from 1 to n and returns
the number of ugly primes number in it.
input: 20
output: 3