C Programming Practice Problems
Functions & Arrays
Problem 1: Lucky Number
Write a function int lucky(int n) that returns 1 if the sum of the digits of the number
is exactly 7; otherwise return 0. Print Lucky or Not Lucky.
Sample Input
124
Sample Output
Lucky
Problem 2: Ticket Price Calculator
A movie ticket costs 300 taka. Write a function
int ticketPrice(int age)
Rules:
• Age below 12 : 50% discount
• Age above 60 : 30% discount
• Otherwise : Full price
Print the final ticket price.
Sample Input
10
Sample Output
150
1
Problem 3: Special Multiple
Write a function
int special(int n)
Return 1 if the number is divisible by both 3 and 5.
Otherwise return 0.
Print YES or NO based on 1 or 0.
Sample Input
45
Sample Output
YES
Problem 4: Count Numbers Greater Than Average
Read an array of N integers.
Find the average and count how many numbers are strictly greater than the average.
Sample Input
5
2 4 6 8 10
Sample Output
2
Problem 5: Replace Negative Numbers
Read an array. Replace every negative number with 0 and print the updated array.
Sample Input
6
3 -2 8 -5 1 -4
Sample Output
3 0 8 0 1 0
Problem 6: Longest Increasing Streak
Read an array. Find the length of the longest consecutive increasing sequence.
Sample Input
8
2 4 6 3 5 7 8 1
Sample Output
4
Explanation:
The longest increasing streak is:
3578
2
Problem 7: Mirror Array
Read an array. Print ”Mirror” if the first half and second half are exactly the same.
Otherwise print ”Not Mirror”. Where N is always even.
Sample Input
6
4 7 9 4 7 9
Sample Output
Mirror
Problem 8: Missing Number
The array contains numbers from 1 to N , but exactly one number is missing.
Find the missing number.
Sample Input
5
1 2 4 5
Sample Output
3