Lab Experiment List
(Any Ten)
1. Write a program to find whether number is even or odd.
Input Output
Test Case 1 2 Even
Test Case 2 4 Even
Test Case 3 3 Odd
Re-Input as integer
Test Case 4 2.5
number
Test Case 5 13 Odd
2. Write a Program in C to calculate and print the electricity bill where the unit consumed
by the user is given from test case. It prints the total amount the consumer has to pay
the charges are as follows
Unit Charges
Up to 199 @1.20
200 and above but less than 400 @1.50
400 and above but less than 600 @1.80
600 and above @2.00
If bill exceed Rs.400 then surcharge of 15% will be charged and the minimum bill
should be of Rs.100/-
Sample Test Cases
Input Output
Test Case 1 50 100.00
Test Case 2 300 517.50
Test Case 3 500 1035.00
Test Case 4 700 1610.00
Test Case 5 80 100.00
Test Case 6 200 300.00
3. Write a program in C to find the sum of the series 1 +11 + 111 + 1111 +…. .. n terms (n
will be given as input from the user and sum will be the output)
Input Output
Test Case 1 4 1234
Test Case 2 6 123456
Test Case 3 5 12345
Test Case 4 7 1234567
4. Write a c program to check whether a given number is a perfect number or not. (Perfect
number is a positive number which sum of all positive divisors excluding that number is
equal to that number. For example 6 is perfect number since divisor of 6 are 1, 2 and 3.
Sum of its divisor is 1 + 2+ 3 = 6)
Input Output
Test Case 1 6 YES
Test Case 2 28 YES
Test Case 3 45 NO
Test Case 4 496 YES
Test Case 5 678 NO
5. Write a C program to determine whether a given number (other than 1) is prime or not
Input Output
Test Case 1 15 NOT PRIME
Test Case 2 17 PRIME
Test Case 3 40 NOT PRIME
Test Case 4 2 PRIME
Test Case 5 71 PRIME
Test Case 6 60 NOT PRIME
6. Write a program in C to print following pattern
*
* * *
* * * * *
* * *
7. Write a program to find a factorial of given number using do while statement.
Input Output
Test Case 1 5 120
Test Case 2 -10 In valid number
Test Case 3 7 5040
Test Case 4 3 6
Test Case 5 4 24
8. Write a program to find find LCM of two numbers using GCF.
Input Output
Test Case 1 4 16 LCM = 16
Test Case 2 25 35 LCM = 175
Test Case 3 25 31 LCM = 775
Test Case 4 30 40 LCM = 120
Test Case 5 7 40 LCM = 280
9. Write a program to accept an integer & find the sum of its digits
Input Output
Test Case 1 1234 Sum of the digits 1234 = 10
Test Case 2 5567 Sum of the digits 5567 = 23
Test Case 3 708 Sum of the digits 708 = 15
Test Case 4 3118 Sum of the digits 3118 = 13
Test Case 5 5006 Sum of the digits 5006 = 11
10. Write a C programme to print the largest and the second largest element of an array
Input Output
65
76
Test Case 1 30 Largest - 76, Second - 70
70
20
100
45
Test Case 2 -486 Largest - 300, Second - 100
300
-560
-9
-13
Test Case 3 -45 Largest - -2, Second - -3
-3
-2
200
300
Test Case 4 4 Largest - 500, Second - 300
0
500
11. Write a program in C which reads a square matrix a[n][n] and print only the elements
that falls in the diagonal starting from a[0][0] to a[n][n] and all other elements printed as 0
(zero).
Input Output
3
1
2
3
1 0 0
4
0 5 0
Test Case 1 5
0 0 9
6
7
8
9
4
1
2
3
4
5
6
1 0 0 0
7
0 6 0 0
8
Test Case 2 0 0 11 0
9
0 0 0 16
10
11
12
13
14
15
16
12. Write a program in c to find the transpose of a matrix
Input Output
3
4
10
10
10
10 10 20 30
20 10 20 30
Test Case 1 20 10 20 30
20 10 20 30
20
30
30
30
30
3
5
11
12
13
14
15 11 21 31
21 12 22 32
22 13 23 33
Test Case 2
23 14 24 34
24 15 25 35
25
31
32
33
34
35
13. C program to count total number of vowel or consonant in a string
Input Output
Total number of
vowel = 6
Amity University Gwalior MP
Test Case 1 Total number of
consonant = 13
Total number of
Indian Institute of Technology, Kharagpur vowel = 14
Test Case 2
Total number of
consonant = 22
14. Write a 'C' code to compare two strings e.g. str1 and str2 and check whether strings are
equal and str1 is greater than str2 or less. Complete the code without using standard string
library.
Sample Test Cases
Input Output
abc
Test Case 1 String 1 is greater than String 2
ABC
ABCD
Test Case 2 Strings are equal
ABCD
ABCD
Test Case 3 String 1 is less than String 2
abcd
123
Test Case 4 Strings are equal
123
15. A Prime number is a natural number greater than 1 which has no positive divisors other
than 1 and itself. Write a 'C' code to read a number and check whether it is prime. A function
isPrime() is used here
Input Output
Test Case 1 5 5 is Prime Number
Test Case 2 10 10 is not Prime Number
Test Case 3 23 23 is Prime Number
Test Case 4 22 22 is not Prime Number
16. Write a program to find the value of s=a^x using recursion function.
Input Output
Test Case 1 5,2 25
Test Case 2 3,3 27
Test Case 3 10,2 10
Test Case 4 2,5 32
17. Consider a C program which will sort number of elements in an ascending by using
bubble sort. We will rewrite the algorithm by using pointer.
Input Output
The sorted elements:
45
5
23
6
Test Case 1 11
11
6
23
5
45
The sorted elements:
11
11
33
22
Test Case 2 22
33
44
44
55
55
The sorted elements:
101
1
102
101
Test Case 3 103
102
401
103
1
401
18. Write a C program to swap two integers using pointers. You have to write a swap function
that will accept the address of two integers and swap their values.
Sample Test Cases
Input Output
12
Test Case 1 num1=45, num2=12
45
4
Test Case 2 num1=10, num2=4
10
5
Test Case 3 num1=3, num2=5
3