SAVEETHA SCHOOL OF ENGINEERING
SAVEETHA INSTITUTE OF MEDICAL AND TECHNICAL SCIENCES
COMPUTER SCIENCE AND ENGINEERING PROGRAMME
CSA02-C PROGRAMMING-QUESTION BANK
ESSAY QUESTIONS
1.
A Pythagorean Triplet is a set of three integers m, n and o such that m2+n2=o2.
Given a limit A, generate all Pythagorean triples with value smaller that given limit A?
Sample Input:
A=12
Sample Output:
(3, 4, 5), (6, 8, 10)
Test cases:
1. A= 10
2. A= -10
3. A= #
4. A=1. 5
5. A=25
2. Ask the user to enter any positive integer. Compile and Execute the C program to
check whether the number is ARMStrong number or not.
Sample Input:
Enter the number to check for strong number: 145
Sample Output:
Factorial of 5 is =120
Factorial of 4 is =24
Factorial of 1is =1
Sum of the factorial of the a given number i145 is =145
145 is the strong number.
Test Cases:
1. 153
2. 26
3. 40585
4. 160
5. 59. 5
3. Find the year of the given anniversary is leap year or not. If leap year then print the next
anniversary, if not leap year then print the previous anniversary.
Sample Input:
Enter the Date: 04/11/1946
Sample Output:
Given Anniversary Year: Non Leap Year.
Anniversary Date: 04/11/1946
Test Cases:
1. 04/11/19. 47
2. 11/15/1936
3. 31/45/1996
4. 64/09/1947
5. 00/00/2000
4. Write a program to print n prime numbers then find the nth Prime number
Sample Input:
N= 3
Sample Output:
3rd Prime number is 5
3 prime numbers after 5 are: 7, 11, 13
Test cases:
1. N = P
2. N = 0
3. N = -4
4. N = 11
5. N = 7. 2
5. Write a program that would sort a list of names in alphabetical order Ascending or
Descending, choice get from the user?
Sample Input:
Banana
Carrot
Radish
Apple
Jack
Order(A/D) : A
Sample Output:
Apple
Banana
Carrot
Jack
Radish
6. Find the Mean, Median, Mode of the array of numbers?
Sample Input:
Array of elements = {16, 18, 27, 16, 23, 21, 19}
Sample Output:
Mean = 20
Median = 19
Mode = 16
Test cases:
1. Array of elements = {26, 28, 37, 26, 33, 31, 29}
2. Array of elements = {1. 6, 1. 8, 2. 7, 1. 6, 2. 3, 2. 1, . 19}
3. Array of elements = {0, 160, 180, 270, 160, 230, 210, 190, 0}
4. Array of elements = {200, 180, 180, 270, 160, 270, 270, 190, 200}
5. Array of elements = {100, 100, 100, 100, 100, 100, 100, 100, 100}
7. Write a program to search the given element using binary search method and display
its position in a linear array.
Sample Input; :
Array of elements = {16, 18, 27, 16, 23, 21, 19}
Element to search = 23
Sample Output:
Given element 23 is found at 5 th position
8. Find the Mth maximum number and Nth minimum number in an array and then find
the sum of it and difference of it.
Sample Input:
Array of elements = {14, 16, 87, 36, 25, 89, 34}
M= 1
N= 3
Sample Output:
1st Maximum Number = 89
3rd Minimum Number = 25
Sum = 114
Difference = 64
Test cases:
1. {16, 16, 16 16, 16}, M= 0, N = 1
2. {0, 0, 0, 0}, M= 1, N = 2
3. {-12, -78, -35, -42, -85}, M= 3 , N = 3
4. {15, 19, 34, 56, 12}, M= 6 , N = 3
5. {85, 45, 65, 75, 95}, M= 5 , N = 7
9. Bubble sort is a straightforward sorting algorithm that checks and swaps elements if
they are not in the intended order. It compares two adjacent elements to find which
one is greater or lesser and switches them based on the given condition until the final
place of the element is found. Write a Program to sort the given numbers in an array
using bubble sort.
Sample Input:
Enter the number of Elements: 5
Enter the Elements:
-2 45 0 11 -9
Output:
-9 -2 0 11 45
10. The selection Sort is assaulting algorithm that works bye buy a finding the smallest
number from the array and then placing it to the first position. the next array that is to
be traversed will start from index next to the position where the smallest number is
placed. Write a Program to sort the given numbers in an array using selection sort.
Sample Input:
Enter the number of Elements: 5
Enter the Elements:
47 34 2189 12
Output:
12 21 34 47 89
11. Write a C program for Inserting an element to the array at the specified index.
Sample Input:
Enter the number of Elements: 5
Enter the Elements:
47 34 2189 12
Element to be inserted 100
At position: 4
Output:
12 21 34 100 47 89
12. Write a C program to take two arrays as input and try to merge or concatenate two
arrays and store the result in third array.
Sample Input:
Enter number of Element in array A: 7
Enter elements: 1 2 3 4 5 6 7
Enter number of Element in array B: 5
11 22 33 44 55
Output:
Merged in array C
1 2 3 4 5 6 7 11 22 33 44 55
13. Write a program in C such that the program will read the elements of a one-
dimensional array, then compares the elements and finds which are the largest two
elements in a given array.
Expected Input and Output:
1. Finding Largest 2 numbers in an array with unique elements:
If we are entering 5 elements (N = 5), with array element values as 2, 4, 5, 8 and 7
then,
The FIRST LARGEST = 8
THE SECOND LARGEST = 7
14. kth smallest element is the minimum possible n such that there are at least k
elements in the array <= n. In other words, if the array A was sorted, then A[k - 1] ( k
is 1based, while the arrays are 0 based )C Program for finding the desired kth smallest
element in an array.
Sample Input:
Enter the number of Elements: 5
Enter K = 3
Enter the Elements:
47 34 2189 12
Output:
34
15. Write a program in C to count the number of vowels and consonants in a string using
a pointer.
Test Data :
Input a string: string
Expected Output :
Number of vowels :
1
Number of constant : 5
Test cases:
1. HYPOTHECATION
2. MATRICULATION
3. MANIPULATION
4. SEDIMENTATION
5. EXPERIMENTATION
16. Write a program in C to find the sum of the series 1! /1+2! /2+3! /3+4! /4+5! /5 using the
function.
Expected Output :
The sum of the series is : 34
17. Write a program using function to calculate the simple interest. Suppose the
customer is a senior citizen. He is being offered 12 percent rate of interest; for all
other customers, the ROI is 10 percent.
Sample Input:
Enter the principal amount: 200000
Enter the no of years: 3
Is customer senior citizen (y/n): n
Sample Output:
Interest: 60000
Test Cases:
1. Principal: 2000 , Years: 0
2. Principal: 20000 , Years: -2
3. Principal: -2000 , Years: 2
4. Principal: 2 , Years: 2000
5. Principal: 0 , Years: 5
18. Write a program to find the Mean of first ‘ N odd numbers, even numbers, square
numbers and cube numbers (using funtion)
Sample Input:
Enter N value : 5
Case: 2
Sample Output:
Mean of first 5 even numbers: 6
Test cases:
1. N = 16
2. N = -8
3. N= 0
4. N = -10. 01
5. N = 11. 22
19. Write a program in C to convert decimal number to binary number using the
function.
Test Data :
Input any decimal number : 65
Expected Output :
The Binary value is : 1000001
Test cases:
1. 111
2. 15. 2
3. 0
4. B12
5. 1A. 2
20. Write a program to enter the marks of a student in four subjects. Then calculate the
total and aggregate, display the grade obtained by the student. If the student scores
an aggregate greater than 75%, then the grade is Distinction. If aggregate is 60>= and
<75, then the grade is First Division. If aggregate is 50 >= and <60, then the grade is
Second Division. If aggregate is 40>= and <50, then the grade is Third Division. Else
the grade is Fail.
Sample Input & Output:
Enter the marks in python: 90
Enter the marks in c programming: 91
Enter the marks in Mathematics: 92
Enter the marks in Physics: 93
Total= 366
Aggregate = 91. 5
DISTINCTION
Test cases:
a) 18, 76, 93, 65
b) 73, 78, 79, 75
c) 98, 106, 120, 95
d) 96, 73, -85, 95
e) 78, 59. 8, 76, 79
21. Write a C programming to find out maximum and minimum of some values using
function which will return an array.
Test Data :
Input 5 values
25
11
35
65
20
Expected Output :
Number of values you want to input: Input 5 values
Minimum value is: 11
Maximum value is: 65
22. In an organization they decide to give bonus to all the employees on New Year. A 5%
bonus on salary is given to the grade A workers and 10% bonus on salary to the grade
B workers. Write a program to enter the salary and grade of the employee. If the
salary of the employee is less than $10, 000 then the employee gets an extra 2% bonus
on salary Calculate the bonus that has to be given to the employee and print the salary
that the employee will get.
Sample Input & Output:
Enter the grade of the employee: B
Enter the employee salary: 50000
Salary=50000
Bonus=5000. 0
Total to be paid: 55000. 0
Test cases:
1. Enter the grade of the employee: A
Enter the employee salary: 8000
2. Enter the grade of the employee: C
Enter the employee salary: 60000
3. Enter the grade of the employee: B
Enter the employee salary: 0
4. Enter the grade of the employee: 38000
Enter the employee salary: A
5. Enter the grade of the employee: B
Enter the employee salary: -8000
23. Write a program in C to check armstrong and perfect numbers using the function.
Test Data :
Input any number: 371
Expected Output :
The 371is an Armstrong number.
The 371is not a Perfect number.
24. Write a program in C to check whether two given strings are an anagram.
Test Data :
Input the first String : spare
Input the second String : pears
Expected Output :
spare and pears are Anagram.
Test cases:
1. X = below , N = elbow
2. X = arc , N = @rc
3. X = study , N = dusty
4. X = laying , N = lying
5. X = abc, N = bac
25. Write a program to enter the marks of n student in four subjects using structure.
Then calculate the total and aggregate, display the grade obtained by the student. If
the student scores an aggregate greater than 75%, then the grade is Distinction. If
aggregate is 60>= and <75, then the grade is First Division. If aggregate is 50 >= and
<60, then the grade is Second Division. If aggregate is 40>= and <50, then the grade
is Third Division. Else the grade is Fail.
Sample Input & Output:
Enter the marks in python: 90
Enter the marks in c programming: 91
Enter the marks in Mathematics: 92
Enter the marks in Physics: 93
Total= 366
Aggregate = 91. 5
DISTINCTION
Test cases:
1. 18, 76, 93, 65
2. 73, 78, 79, 75
3. 98, 106, 120, -95
4. 96, 73, AA, 95
5. 78, 59. 8, **, 79
2.
26. Mr. Johnson would like to know how many As, Bs, Cs, Ds, and Fs his
students received on a test. He has n students who took the test. He would
like to enter the student number and the number grade for the test for each
student using structure. Develop the solution to print out each student’ s
student number, number grade and the total number of As, Bs, Cs, Ds,
and Fs. His grading scale is as follows: 90–100 is an A, 78–89 is a B, 65–77
is a C, 50–64 is a D, and below 50 is an F.
Sample Input :
Enter No. Students: 1
Enter student 1Number , Grade : 2001, A
Sample Output:
Student 1details:
Number : 2001
Grade : A
Total no. A: 1, B: 0, c=0, D=0, F=0,
Test Cases:
No. Student : 4 (Any details of student Number , Grade )
No. Student: 5
No. Student: 1( 2004, 28)
No. Student: A
No. Student: 1( xxx, A)