PROGRAMMING IN C
LEVEL – 3 (ARRAYS IN C)
1. Find the First Non-Repeating Element
Problem Statement
Given an array of integers, find the first element that does not repeat in the array.
If all elements repeat, print "No unique element".
Input Format
• First line contains integer n (size of array)
• Second line contains n integers
Output Format
Print the first non-repeating element.
Sample Input
7
4512041
Sample Output
First non-repeating element: 5
2. Leaders in an Array
Problem Statement
An element is called a leader if it is greater than all elements to its right side.
Print all leaders in the array.
(Last element is always a leader.)
Input Format
• First line contains integer n
• Second line contains n integers
Output Format
Print all leaders separated by space.
Sample Input
6
16 17 4 3 5 2
Sample Output
Leaders: 17 5 2
3. Find the Equilibrium Index
Problem Statement
Find an index in the array where the sum of elements before it equals the sum of elements after it.
If no equilibrium index exists, print -1.
Input Format
• First line: integer n
• Second line: n integers
Output Format
Print the equilibrium index.
Sample Input
7
-7 1 5 2 -4 3 0
Sample Output
Equilibrium index: 3
(Because sum of left = sum of right = -1)
4. Rotate Array by K Positions (Without Extra Array)
Problem Statement
Given an array of n elements, rotate the array left by k positions.
Input Format
• First line contains n
• Second line contains n integers
• Third line contains k
Output Format
Print the rotated array.
Sample Input
5
12345
2
Sample Output
Rotated array: 3 4 5 1 2
5. Find the Second Largest Distinct Element
Problem Statement
Find the second largest distinct element in the array.
If it does not exist, print "Not possible".
Input Format
• First line: integer n
• Second line: n integers
Output Format
Print the second largest distinct element.
Sample Input
6
10 5 20 20 4 5
Sample Output
Second largest element: 10
LEVEL – 4(STRING AND IT’S OPERATIONS)
1. Longest Word in a Sentence
Problem Statement
Write a C program to find the longest word in a given sentence.
If multiple words have the same maximum length, print the first one.
Input Format
A single line containing a sentence.
Output Format
Print the longest word.
Sample Input
C programming builds strong problem solving skills
Sample Output
Longest word: programming
2. Check if Two Strings are Rotations of Each Other
Problem Statement
Two strings are said to be rotations if one string can be obtained by rotating the other.
Example:
ABCD → rotations → BCDA, CDAB, DABC.
Write a program to check whether two strings are rotations of each other.
Input Format
Two lines containing string1 and string2.
Output Format
Print
Strings are rotations
or
Strings are not rotations.
Sample Input
ABCD
CDAB
Sample Output
Strings are rotations
3. Remove Duplicate Characters from a String
Problem Statement
Write a program to remove duplicate characters from a string while keeping the first occurrence.
Input Format
A string.
Output Format
Print the string after removing duplicates.
Sample Input
programming
Sample Output
progamin
4. Most Frequent Character in a String
Problem Statement
Write a program to find the character that appears the most number of times in a string.
Ignore spaces.
Input Format
A string.
Output Format
Print the most frequent character and its count.
Sample Input
data structures
Sample Output
Most frequent character: t
Frequency: 3
5. Check if a String is a Pangram
Problem Statement
A pangram is a sentence that contains every letter of the alphabet at least once.
Write a program to check whether the given string is a pangram.
Input Format
A sentence.
Output Format
Print
Pangram
or
Not a Pangram.
Sample Input
the quick brown fox jumps over the lazy dog
Sample Output
Pangram
LEVEL – 5(FUNCTIONS AND RECURSION)
1. Recursive Palindrome Check
Problem Statement
Write a C program using recursion to check whether a given string is a palindrome.
Use a function that compares characters recursively from both ends of the string.
Input Format
A single line containing a string.
Output Format
Print:
• Palindrome if the string is a palindrome
• Not a Palindrome otherwise
Sample Input
madam
Sample Output
Palindrome
2. Recursive Sum of Digits Until Single Digit
Problem Statement
Write a recursive function that repeatedly sums the digits of a number until the result becomes a
single digit.
Example
9875 → 9+8+7+5 = 29
29 → 2+9 = 11
11 → 1+1 = 2
Input Format
A single integer n.
Output Format
Print the final single digit.
Sample Input
9875
Sample Output
Final single digit: 2
3. Recursive Binary Search using Functions
Problem Statement
Write a program to perform Binary Search using recursion.
Create a function that recursively searches for an element in a sorted array.
Input Format
First line → integer n
Second line → n sorted integers
Third line → element to search
Output Format
Print the index of the element (0-based).
If not found, print Element not found.
Sample Input
5
2 4 6 8 10
6
Sample Output
Element found at index 2
4. Recursive Power Function (Without pow())
Problem Statement
Write a recursive function to calculate xⁿ (x raised to power n) without using any library functions.
Input Format
Two integers x and n.
Output Format
Print the value of xⁿ.
Sample Input
25
Sample Output
Result: 32
5. Generate Fibonacci Series using Recursion
Problem Statement
Write a program using recursion to generate Fibonacci numbers up to n terms.
Fibonacci rule:
F(n) = F(n-1) + F(n-2)
Input Format
An integer n representing number of terms.
Output Format
Print the Fibonacci sequence.
Sample Input
7
Sample Output
Fibonacci Series: 0 1 1 2 3 5 8