C Notes
Collection of 50+ important C programs frequently asked in exams and interviews covering patterns, arrays, strings, numbers, recursion, and sorting algorithms.
This collection contains the most important C programs asked in exams, lab assignments, and interviews. Each program includes a working solution with output. Practice these to build strong programming fundamentals.
Number Programs
1. Check Prime Number
29 is Prime
2. Fibonacci Series
0 1 1 2 3 5 8 13 21 34
3. Factorial (Iterative and Recursive)
5! = 120 (iterative) 5! = 120 (recursive)
4. Reverse a Number
#include <stdio.h>
int reverseNumber(int n) {
int reversed = 0;
while (n != 0) {
reversed = reversed * 10 + n % 10;
n /= 10;
}
return reversed;
}
int main() {
printf("Reverse of 12345: %d\n", reverseNumber(12345));
return 0;
}Reverse of 12345: 54321
5. Check Palindrome Number
#include <stdio.h>
int isPalindrome(int n) {
int original = n, reversed = 0;
while (n > 0) {
reversed = reversed * 10 + n % 10;
n /= 10;
}
return original == reversed;
}
int main() {
printf("121: %s\n", isPalindrome(121) ? "Palindrome" : "Not Palindrome");
printf("123: %s\n", isPalindrome(123) ? "Palindrome" : "Not Palindrome");
return 0;
}121: Palindrome 123: Not Palindrome
6. Armstrong Number
153: Armstrong 370: Armstrong
7. GCD and LCM
#include <stdio.h>
int gcd(int a, int b) {
while (b != 0) { int t = b; b = a % b; a = t; }
return a;
}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int main() {
printf("GCD(12, 18) = %d\n", gcd(12, 18));
printf("LCM(12, 18) = %d\n", lcm(12, 18));
return 0;
}GCD(12, 18) = 6 LCM(12, 18) = 36
8. Power of a Number
#include <stdio.h>
long power(int base, int exp) {
long result = 1;
while (exp > 0) {
if (exp % 2 == 1) result *= base;
base *= base;
exp /= 2;
}
return result;
}
int main() {
printf("2^10 = %ld\n", power(2, 10));
printf("3^5 = %ld\n", power(3, 5));
return 0;
}2^10 = 1024 3^5 = 243
Array Programs
9. Find Largest and Smallest Element
Largest: 89, Smallest: 7
10. Reverse an Array
5 4 3 2 1
11. Bubble Sort
11 12 22 25 34 64 90
12. Binary Search
Found at index: 5
String Programs
13. Reverse a String
Reversed: dlroW olleH
14. Check String Palindrome
madam: Palindrome hello: Not
15. Count Vowels and Consonants
Vowels: 3, Consonants: 7, Digits: 3, Spaces: 2
Pattern Programs
16. Star Pyramid
* *** ***** ******* *********
17. Number Triangle
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Recursion Programs
18. Tower of Hanoi
#include <stdio.h>
void hanoi(int n, char from, char to, char aux) {
if (n == 0) return;
hanoi(n - 1, from, aux, to);
printf("Move disk %d: %c -> %c\n", n, from, to);
hanoi(n - 1, aux, to, from);
}
int main() {
hanoi(3, 'A', 'C', 'B');
return 0;
}Move disk 1: A -> C Move disk 2: A -> B Move disk 1: C -> B Move disk 3: A -> C Move disk 1: B -> A Move disk 2: B -> C Move disk 1: A -> C
19. Sum of Digits (Recursive)
#include <stdio.h>
int sumDigits(int n) {
if (n == 0) return 0;
return n % 10 + sumDigits(n / 10);
}
int main() {
printf("Sum of digits of 12345: %d\n", sumDigits(12345));
return 0;
}Sum of digits of 12345: 15
Sorting Algorithms
20. Selection Sort
10 13 14 29 37
21. Insertion Sort
5 6 11 12 13
Quick Reference: All Programs
| # | Program | Key Concept |
|---|---|---|
| 1-8 | Number programs | Loops, modulus, recursion |
| 9-12 | Array programs | Indexing, searching, sorting |
| 13-15 | String programs | Character arrays, traversal |
| 16-17 | Pattern programs | Nested loops |
| 18-19 | Recursion | Base case, divide & conquer |
| 20-21 | Sorting | Comparison-based algorithms |
Summary
These programs form the foundation of C programming proficiency. Each one teaches a specific concept – from basic loops and conditions to recursion and algorithms. Practice writing them from memory, then try variations (e.g., reverse pyramid, merge sort, string compression). The ability to code these quickly and correctly is what interviewers and examiners look for.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Important C Programs – 50+ Frequently Asked Programs with Solutions.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this C Programming topic.
Search Terms
c-programming, c programming, programming, resources, important, programs, important c programs – 50+ frequently asked programs with solutions
Related C Programming Topics