C Programs
C Programs
*5. WAP in C to swap two number with using/without using third variable.
7. WAP in C to find the distance between two points (x1, y1) and (x2, y2).
*7. WAP in C to check whether a given number is odd or even and number is entered by user.
*9. WAP in C to check whether year is leap year or not and year is entered by user.
*10. WAP in C to print the largest number among three number and numbers are entered by user.
*11. WAP in C to calculate the percentage of marks of five subjects of a student and print whether he is failed or passed with
division using nested if-else, where marks are entered by user.
12. There are 3 company, Facebook, Flipkart and TCS. The eligibility criteria of companies are as follows:
*13. WAP in C to check whether entered character is consonant or vowel using switch statement.
1 R RED
B BLUE
2 R RAT
B BAT
17. WAP in C to calculate a b of given numbers a and b and numbers are entered by user.
*27. WAP in C to find sum of 1/1! + 1/2! + 1/3! + ……….. + 1/n! where n will be entered by user.
33. WAP in C to find the all Pythagorean triplets less than 100.
1 * 1 1
2 3 * * 12 21
4 5 6 * * 123 321
7 8 9 0 * * * * * 1234 4321
1234554321
1 1 1 1 2 3 4 5 A
2 2 2 2
33 3 3 16 17 18 19 6 B A
4 4 4
33 3 3 15 24 25 20 7 C B A
2 2 2 2
1 1 1 14 23 22 21 8 D C B A
13 12 11 10 9
1 * * ****
* *
2 3 2 * A * * *
*******
3 4 5 4 3 * A * A * * *
* *
4 5 6 7 6 5 4 * A * A * A * **** *
35. Given a matrix of 2D array of n rows and m columns. Write a C program to print matrix in ZIG-ZAG fashion as shown in figure.
Example:
Input: 123
456
789
Output: 124753689
*37. WAP in C to accept 50 numbers and print the smallest and largest numbers among them.
38. WAP in C to print the odd position elements of an array and, also calculate their sum, where elements of array are entered by
user.
39. Write a program in C to print the all elements of an array who have value greater than average of elements of same array.
*40. WAP in C to fill third array in ascending order from two sorted arrays.
41. WAP in C to enter an element and find whether this element is in the array.
44. Write a program in C to print the repeated elements of an array and, count how many times they are repeated.
For example, suppose an array contains following elements:
2 0 7 2 2 0 1 2 0 9 1
Find the output according to following manner (in general).
Element Frequency
2 4
0 3
7 1
1 2
9 1
45. Write a program in C to subtract two matrices.
47. Write a program in C to print the border elements of a matrix of M x N where M, N > 3.
48.Write a program in C to print the diagonals elements of a matrix and, also calculate the sum of diagonals elements of a matrix.
50. 6 x 6 matrix is entered through the keyboard. Write a program in C to obtain the determinant value of this matrix.
51. WAP in C which accept the radius and height in main function and pass them to a function. Function calculate the area, volume
and perimeter of a cylinder and their values get printed in main function.
54. Write a program in C to find GCD of two number using recursion function.
55. Write a program in C to solve the TOWER of HANOI problem using recursion function.
56. Write a program in C to find the Armstrong numbers between 1 to n using function.
57. WAP in C which accepts a string and finds, if it is palindrome or not. For example, abeabba is such a string.
59. WAP in C that extracts part of the given string from the specified position. For example, if string is “Working with strings is
fun”, then if from position 4, 4 characters are to be extracted then the program should return string as “king”.
*60. WAP in C to reverse the string for example, input string is as “I am in MMMUT” and output string should be “MMMUT in
am I”.
61. WAP in C to read a string as “Amit Kumar Singh” and give the output as A. K. Singh.
WAP in C to print the names of all students who joined in a particular year.
*65. Suppose there are 100 employees in a company. Write a program in C to print the details of employees of the company who
have experiences more than 10 years by passing structure in function and access the details by using the pointer and, employee’s
details are inputted by user. Details contains following information:
Employee _ID
Employee _Name
Employee _Experience
Employee _Department
66. Write a function that compare two given dates. To store a date use structure that contains three members namely day, month,
*67. Write a program in C to print the details of 100 books using union. And details contain following information:
Book_Name
Page_No
Book_Price
68. Write a program in C to store n elements in an array and print the elements using pointer.
69. Write a program in C to print all permutations of a given string using pointers.
70. Write a C function that takes two set as input and prints cartesian product of two sets. e.g.
Input: A = {1, 2}, B = {3, 4}
71.Given an array of elements of length N, ranging from 1 to N. All elements may not be present in the array. If element is not
present, then there will be -1 present in the array. Write a C function that rearrange the array such that A[i] = i and if i is not
72. Given an array of n integers (duplicates allowed). Write a C function that prints “Yes” if it is a set of contiguous integers else
print “No”.
Examples:
Output: Yes
Output: No
73. Given an amount, write a C function that find the minimum number of notes of different denominations that sum up to the given
amount. Starting from the highest denomination note, try to accommodate as many notes possible for given amount. Suppose
notes of values {2000, 500, 200, 100, 50, 20, 10, 5, 1} are only available.
74. Given an array, write a C function that find maximum triplet sum in the array
Output: 21
10 + 8 + 3 = 21
Output: 37
20 + 9 + 8 = 37
75. Given a square matrix, write a C function that checks the matrix is in lower triangular form or not. A square matrix is called
lower triangular if all the entries above the main diagonal are zero.
76. Given a robot which can only move in four directions, UP(U), DOWN(D), LEFT(L), RIGHT(R). Given a string consisting of
instructions to move. Write a program in C that output the co-ordinates of robot after the executing the instructions. Initial
Therefore, final position after the complete movement is: (-1, -1)
77. Here given a range from low to high and given a number k. Write a C function to find out the number of count which a number
Output: 4
Output: 3
78. Given two arrays arr1[] and arr2[], Write a C function to combine two arrays in such a way that the combined array has alternate
elements of both. If one array has extra element, then these elements are appended at the end of the combined array.
79. Given two arrays A [] and B[] of size n. It is given that both arrays individually contain distinct elements. Write a C function to
Input: A [] = {1, 5, 3, 8}
B [] = {5, 4, 6, 7}
Output: 29
1 + 3 + 4 + 6 + 7 + 8 = 29
B [] = {5, 1, 8, 3}
Output: 0
All elements are common.
80. Given an array of unique integers where each integer of the given array lies in the range [1, N]. The size of array is (N-4). No
Single element is repeated. Hence four numbers from 1 to N are missing in the array. Write a C function to find the 4 missing
Output: 1 4 7 8
Output: 2 6 11 12
81. Given an array a[] and an element x, find number of occurrences of x in a[].
x=5
Output: 3
x=4
Output: 0
82. Given a positive integer n. Write a C function to print the pyramid pattern as described in the
below.
Input: 2
Output:
22
Input: 3
Output:
22
333
22
83. Given a square matrix of order n*n, write a C function to print elements of the matrix in Z form
4, 5, 6,
7, 8, 9}
Output: 1 2 3 5 7 8 9
4, 1, 14, 8,
2, 20, 1, 9,
1, 2, 55, 4}
Output: 5 19 8 7 14 20 1 2 55 4
84. Given a circle (coordinates of centre and radius) and a point (coordinate), find if the point lies inside or on the circle, or not.
Examples:
Output: Inside
Output: Outside
85. Given an array of N integers. Write a C function to find an index such that Frequency of Even numbers on its left side is equal
to the frequency of even numbers on its right sides or frequency of odd numbers on its left side is equal to the frequency of Odd
numbers on its right sides. If No such index exists in an array print -1 Else print required index. Note- (If more than one index
Examples:
Input: arr[] = {4, 3, 2, 1, 2, 4}
Output: index = 2
Explanation: At index 2, there is one odd number on its left and one odd on its right.
86. You are given an array of n-elements with a basic condition that occurrence of greatest element is more than once. Write a C
Examples:
Input: arr[] = {3, 5, 2, 3, 5, 3, 5}
Output: Minimum Distance = 2
Explanation: Greatest element is 5 and its index are 1, 4 and 6. Resulting minimum distance of 2 from position 4
to 6.
Input: arr[] = {1, 1, 1, 1, 1, 1}
Output: Minimum Distance = 1
Explanation: Greatest element is 1 and its index are 0, 1, 2, 3, 4 and 5. Resulting minimum distance of 1.
87.You are given an array. Write a C function to sort the even positioned elements in the ascending order and the odd positioned
88. Given an array of numbers, write a C function to find the number among them such that all numbers are divisible by it. If not
possible print 1.
Examples:
Input: arr = {25, 20, 5, 10, 100}
Output: 5
Explanation: 5 is an array element which divides all numbers.
Input: arr = {9, 3, 6, 2, 15}
Output: -1
Explanation: No numbers are divisible by any array element
89.Given a n x n matrix. Write a C function to sort the matrix row-wise and column wise.
Examples:
Input: mat[][] = { {4, 1, 3},
{9, 6, 8},
{5, 2, 7}}
Output: 134
257
689
90. Given a n x n matrix. Write a C function to sort the given matrix in strict order. Here strict order means that matrix is sorted in
a way such that all elements in a row are sorted in increasing order and for row ‘i’, where 1 <= i <= n-1, first element of row 'i'
Examples:
Input: mat[][] = { {5, 4, 7},
{1, 3, 8},
{2, 9, 6}}
Output: 123
456
789
91. Given a number n. Write a C function to find out number of Reflexive Relation on a set of first n natural numbers {1, 2, ..n}.
Examples:
Input: n = 2
Output: 4
The given set A = {1, 2}. The following are reflexive relations on A * A:
{{1, 1), (2, 2)}, {(1, 1), (2, 2), (1, 2)}, {(1, 1), (2, 2), (1, 2), (2, 1)},
{(1, 1), (2, 2), (2, 1)}
Input: n = 3
Output: 64
The given set is {1, 2, 3}. There are 64 reflexive relations on A * A.