S.
Name of Program Page Teacher’s
No. No. Sign
Write a program in C to check whether a number entered by user is prime
1. number or not.
Write a program in C to print the sum and product of its digits of an integer
2. number entered by user and reverse it.
Write a program in C to calculate the HCF and LCM of two numbers entered
3. by user.
Write a program in C for finding the binary equivalent of the decimal number
4. entered by user.
Write a program in C to input the basic salary of an employee from the user
5. and calculate the gross salary as per given HRA and DA.
Write a program in C to input marks of five subjects, find percentage and
6. using switch case display whether the student passes or fails.
Write a program in C to input date, month and year and using switch case
7. display month in words.
Write a program in C to input a number and make functions to check whether
8. it is even or odd and whether it is a palindrome or not.
Write a program in C to print the given four number patterns up to n, where n
9. is any natural number entered by user.
Write a program in C to calculate the factorial of a number entered by user
10. using recursion.
Write a program in C to print the Fibonacci series up to n terms where n is
11. entered by user.
Write a program in C to print the area and circumference of a circle using call
12. by value and call by reference.
Write a program in C which prompts the user for a list of prices of given
13. items and prints all prices higher than the average price.
Write a program in C to create an array of 10 integers, accept values from
user and count how many are equal to, greater than and less than a given
14. number.
Write a program in C to input two matrices of order 3×3, add them and print
15. the result.
Write a program in C to input two matrices of order 3×3, multiply them and
16. print the result.
17. Write a program in C to determine the transpose of a matrix.
Write a menu driven program in C to copy one string to another, concatenate
18. two strings, compare two strings, find length of a string and reverse a string.
Write a program in C to reverse a string using recursion and check whether it
19. is a palindrome string or not.
Write a program in C to input roll number and marks of five subjects,
20. calculate total and percentage and display whether the student passes or fails.
Write a C program to sort an array using Bubble sort and display the array
21. after each pass.
Write a C program to sort an array using Selection sort and count the total
22. number of swaps.
Write a C program to sort an array using Insertion sort and show the array
23. after each insertion step.
24. Write a program in C to implement linear search using arrays.
25. Write a program in C to implement binary search using arrays.
1. Write a program in C to check whether a number entered by user is
prime number or not.
#include <stdio.h>
int main() {
int n, i;
int isPrime = 1; // assume prime at start
printf("Enter a positive number: ");
scanf("%d", &n);
if (n <= 1) {
isPrime = 0; // 0 and 1 are not prime
} else {
// check from 2 to n-1
for (i = 2; i < n; i++) {
if (n % i == 0) {
isPrime = 0; // found a divisor
break;
if (isPrime == 1)
printf("%d is a prime number.\n", n);
else
printf("%d is not a prime number.\n", n);
return 0;}
2. Write a program in C to print the sum and product of digits of an
integer number.
#include <stdio.h>
int main() {
int n, temp, digit;
int sum = 0;
int product = 1;
int reverse = 0;
printf("Enter an integer: ");
scanf("%d", &n);
temp = n;
if (temp < 0) temp = -temp; // ignore sign for digits
while (temp != 0) {
digit = temp % 10; // last digit
sum = sum + digit;
product = product * digit;
reverse = reverse * 10 + digit;
temp = temp / 10; // remove last digit }
printf("Sum of digits = %d\n", sum);
printf("Product of digits = %d\n", product);
if (n < 0)
printf("Reverse = -%d\n", reverse);
else
printf("Reverse = %d\n", reverse);
return 0;}
3. write a program in c to check whether a number entered by user is
a Armstrong number or not.
#include <stdio.h>
int main() {
int n, rem, sum = 0, temp;
printf("Enter a number: ");
scanf("%d", &n);
temp = n;
while(n > 0) {
rem = n % 10;
sum += rem * rem * rem;
n /= 10;
if(sum == temp)
printf("Armstrong number");
else
printf("Not Armstrong");
return 0;
}
5. Write a program in C calculate HCF and LCM of the two number.
#include <stdio.h>
int main() {
int a, b;
int hcf, lcm;
int i, min;
printf("Enter two positive integers: ");
scanf("%d%d", &a, &b);
// find HCF by checking all numbers up to smaller number
min = (a < b) ? a : b;
hcf = 1;
for (i = 1; i <= min; i++) {
if (a % i == 0 && b % i == 0) {
hcf = i;
lcm = (a * b) / hcf;
printf("HCF = %d\n", hcf);
printf("LCM = %d\n", lcm);
return 0;}
5. Write a program in C for finding the binary equivalent of the
decimal number entered by user.
#include <stdio.h>
int main() {
int n;
int bin[32];
int i = 0, j;
printf("Enter a non‑negative decimal number: ");
scanf("%d", &n);
if (n == 0) {
printf("Binary = 0\n");
return 0;
// store remainders
while (n > 0) {
bin[i] = n % 2;
n = n / 2;
i++; }
printf("Binary = ");
// print in reverse order
for (j = i - 1; j >= 0; j--) {
printf("%d", bin[j]);}
printf("\n");
return 0;}
[Link] a program in C to input the basic salary of an employee from
the user. Calculate the gross salary on the following basis.
1–4000 ⇒ HRA 10%, DA 50%
4001–8000 ⇒ HRA 20%, DA 60%
8001–12000 ⇒ HRA 25%, DA 70%
Above 12000 ⇒ HRA 30%, DA 80%)
#include <stdio.h>
int main() {
float basic, hra, da, gross;
printf("Enter basic salary: ");
scanf("%f", &basic);
if (basic <= 4000) {
hra = 0.10f * basic;
da = 0.50f * basic;
} else if (basic <= 8000) {
hra = 0.20f * basic;
da = 0.60f * basic;
} else if (basic <= 12000) {
hra = 0.25f * basic;
da = 0.70f * basic;
} else {
hra = 0.30f * basic;
da = 0.80f * basic;
gross = basic + hra + da;
printf("HRA = %.2f\n", hra);
printf("DA = %.2f\n", da);
printf("Gross salary = %.2f\n", gross);
return 0;
}
[Link] a program in C to input date, month and year from the user
and using switch case display month in words (e.g. input Date = 6,
Month = 7, Year = 2025 → output “6 July 2025”
#include <stdio.h>
int main() {
int d, m, y;
printf("Enter date (dd mm yyyy): ");
scanf("%d%d%d", &d, &m, &y);
printf("%d ", d); // print day first
switch (m) {
case 1: printf("January "); break;
case 2: printf("February "); break;
case 3: printf("March "); break;
case 4: printf("April "); break;
case 5: printf("May "); break;
case 6: printf("June "); break;
case 7: printf("July "); break;
case 8: printf("August "); break;
case 9: printf("September "); break;
case 10: printf("October "); break;
case 11: printf("November "); break;
case 12: printf("December "); break;
default: printf("Invalid-month "); }
printf("%d\n", y); // print year
return 0;
[Link] a program in C to input a number and make a function to
check whether the passed number is an even or odd number. Also
make a different function to check that the passed number is a
palindrome number or not.
#include <stdio.h>
int isEven(int n) {
if (n % 2 == 0)
return 1;
else
return 0;
int isPalindrome(int n) {
int temp = n;
int rev = 0, d;
if (n < 0) return 0; // treat negative as not palindrome
while (temp != 0) {
d = temp % 10;
rev = rev * 10 + d;
temp = temp / 10;
if (rev == n)
return 1;
else
return 0;
int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);
if (isEven(n))
printf("%d is even.\n", n);
else
printf("%d is odd.\n", n);
if (isPalindrome(n))
printf("%d is a palindrome.\n", n);
else
printf("%d is not a palindrome.\n", n);
return 0;
}
9. Write a program in C to print the following pattern up to n where n
is any natural number entered by user
(i)
1
12
123…
(ii)
1
22
333…
(iii)
1
21
321…
(iv)
1
12
1 2 3 … n, then reverse down (like a pyramid of numbers).
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter value of n: ");
scanf("%d", &n);
// (i)
printf("\nPattern (i):\n");
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++)
printf("%d ", j);
printf("\n"); }
// (ii)
printf("\nPattern (ii):\n");
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++)
printf("%d ", i);
printf("\n"); }
// (iii)
printf("\nPattern (iii):\n");
for (i = 1; i <= n; i++) {
for (j = i; j >= 1; j--)
printf("%d ", j);
printf("\n"); }
// (iv) – full pyramid up to n and back
printf("\nPattern (iv):\n");
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++)
printf("%d ", j);
printf("\n"); }
for (i = n - 1; i >= 1; i--) {
for (j = 1; j <= i; j++)
printf("%d ", j);
printf("\n"); }
return 0;
}
[Link] a program in C to calculate the factorial of a number
entered by user using recursion.
#include <stdio.h>
long fact(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * fact(n - 1);}
int main() {
int n;
long f;
printf("Enter a non‑negative integer: ");
scanf("%d", &n);
if (n < 0) {
printf("Factorial not defined for negative numbers.\n");
} else {
f = fact(n);
printf("Factorial of %d = %ld\n", n, f);
return 0; }
[Link] a program in C to print the Fibonacci series up to n terms
where the number n is entered by user using recursion.
#include <stdio.h>
int main() {
int n, i;
int a = 0, b = 1, c;
printf("Enter number of terms: ");
scanf("%d", &n);
if (n <= 0) {
printf("No terms to print.\n");
return 0;
printf("Fibonacci series:\n");
if (n >= 1)
printf("%d ", a);
if (n >= 2)
printf("%d ", b);
for (i = 3; i <= n; i++) {
c = a + b;
printf("%d ", c);
a = b;
b = c; }
printf("\n");
return 0;
12. Write a program in C to print the area and circumference of circle
using pointer, call by value and call by reference.
#include <stdio.h>
#define PI 3.14159
/* call by value: returns area */
float areaValue(float r) {
return PI * r * r; }
/* call by reference: fills area and circumference using pointers */
void circleRef(float r, float *a, float *c) {
*a = PI * r * r;
*c = 2 * PI * r;
int main() {
float r, area1, area2, circ;
printf("Enter radius of circle: ");
scanf("%f", &r);
/* call by value */
area1 = areaValue(r);
printf("Using call by value, Area = %.2f\n", area1);
/* call by reference */
circleRef(r, &area2, &circ);
printf("Using call by reference, Area = %.2f\n", area2);
printf("Circumference = %.2f\n", circ);
return 0; }
13. Write a program in C which prompts the user for a list of the
prices of given items and find out all the prices that are higher than
the calculated average.
#include <stdio.h>
int main() {
float price[50];
int n, i;
float sum = 0, avg;
printf("How many prices (max 50)? ");
scanf("%d", &n);
printf("Enter %d prices:\n", n);
for (i = 0; i < n; i++) {
scanf("%f", &price[i]);
sum = sum + price[i];
avg = sum / n;
printf("Average price = %.2f\n", avg);
printf("Prices greater than average:\n");
for (i = 0; i < n; i++) {
if (price[i] > avg) {
printf("%.2f\n", price[i]);
}
return 0;
14. Write a program in C to create an array of 10 integers. Accept
values from the user in that array. Input another number and find out
how many numbers are equal to the number passed, how many are
greater and how many are less than the number passed.
#include <stdio.h>
int main() {
int a[10];
int i, num;
int equal = 0, greater = 0, less = 0;
printf("Enter 10 integers:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &a[i]); }
printf("Enter number to compare: ");
scanf("%d", &num);
for (i = 0; i < 10; i++) {
if (a[i] == num)
equal++;
else if (a[i] > num)
greater++;
else
less++; }
printf("Equal to %d : %d elements\n", num, equal);
printf("Greater than %d : %d elements\n", num, greater);
printf("Less than %d : %d elements\n", num, less);
return 0;
}
15. Write a program in C to input two matrix of the order 3×3 and
add them and print.
#include <stdio.h>
int main() {
int a[3][3], b[3][3], sum[3][3];
int i, j;
printf("Enter elements of first 3x3 matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &a[i][j]);
printf("Enter elements of second 3x3 matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &b[i][j]);
// add the matrices
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
sum[i][j] = a[i][j] + b[i][j];
printf("Sum matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", sum[i][j]);
printf("\n");
return 0;
}
16. Write a program in C to input two matrix of the order 3×3 and
multiply them and print.
#include <stdio.h>
int main() {
int a[3][3], b[3][3], c[3][3];
int i, j, k;
printf("Enter elements of first 3x3 matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &a[i][j]);
printf("Enter elements of second 3x3 matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &b[i][j]);
// matrix multiplication
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
c[i][j] = 0;
for (k = 0; k < 3; k++) {
c[i][j] = c[i][j] + a[i][k] * b[k][j];
printf("Product matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", c[i][j]);
printf("\n");
return 0;
}
17. Write a program in C to determine the transpose of a matrix.
#include <stdio.h>
int main() {
int a[10][10], t[10][10];
int r, c, i, j;
printf("Enter rows and columns of matrix: ");
scanf("%d%d", &r, &c);
printf("Enter elements of matrix (%d x %d):\n", r, c);
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
scanf("%d", &a[i][j]); }
// find transpose
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
t[j][i] = a[i][j]; }
printf("Transpose matrix:\n");
for (i = 0; i < c; i++) { // note: rows and columns swapped
for (j = 0; j < r; j++) {
printf("%d ", t[i][j]);
} printf("\n");
return 0; }
18. Write a menu-driven program in C to:
a) Copy the contents of one string to another string.
b) Concatenate two strings.
c) Compare two strings.
d) To calculate the length of a string.
#include <stdio.h>
#include <string.h>
int main() {
char s1[100], s2[100], temp[100];
int choice, result;
while (1) {
printf("\nMenu\n");
printf("1. Copy string\n");
printf("2. Concatenate strings\n");
printf("3. Compare strings\n");
printf("4. Length of string\n");
printf("5. Reverse string\n");
printf("6. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
getchar(); // clear newline
switch (choice) {
case 1:
printf("Enter source string: ");
gets(s1);
strcpy(s2, s1);
printf("Copied string = %s\n", s2);
break;
case 2:
printf("Enter first string: ");
gets(s1);
printf("Enter second string: ");
gets(s2);
strcpy(temp, s1);
strcat(temp, s2);
printf("Concatenated string = %s\n", temp);
break;
case 3:
printf("Enter first string: ");
gets(s1);
printf("Enter second string: ");
gets(s2);
result = strcmp(s1, s2);
if (result == 0)
printf("Both strings are equal.\n");
else if (result < 0)
printf("First string is smaller.\n");
else
printf("First string is greater.\n");
break;
case 4:
printf("Enter a string: ");
gets(s1);
printf("Length = %d\n", (int)strlen(s1));
break;
case 5:
printf("Enter a string: ");
gets(s1);
strcpy(temp, s1);
strrev(temp); // if not available, can reverse manually
printf("Reverse = %s\n", temp);
break;
case 6:
return 0;
default:
printf("Wrong choice.\n");
}
19. Write a program in C to reverse the string using recursion and
check if it is a palindrome string or not.
#include <stdio.h>
#include <string.h>
void reverseRec(char s[], int start, int end) {
char temp;
if (start >= end)
return;
temp = s[start];
s[start] = s[end];
s[end] = temp;
reverseRec(s, start + 1, end - 1); }
int main() {
char s[100], copy[100];
printf("Enter a string: ");
gets(s);
strcpy(copy, s);
reverseRec(copy, 0, strlen(copy) - 1);
printf("Reverse string = %s\n", copy);
if (strcmp(s, copy) == 0)
printf("It is a palindrome string.\n");
else
printf("It is not a palindrome string.\n");
return 0; }
20. Write a program in C to input roll number and marks of five
subjects and check if a student passes or fails (if marks of each
subject is greater than or equal to 33 then pass, otherwise fail). Also
print total and percentage.
#include <stdio.h>
int main() {
int roll;
float m1, m2, m3, m4, m5;
float total, per;
printf("Enter roll number: ");
scanf("%d", &roll);
printf("Enter marks of 5 subjects: ");
scanf("%f%f%f%f%f", &m1, &m2, &m3, &m4, &m5);
total = m1 + m2 + m3 + m4 + m5;
per = total / 5.0;
printf("\nRoll = %d\n", roll);
printf("Total marks = %.2f\n", total);
printf("Percentage = %.2f\n", per);
// pass if at least 33 in every subject
if (m1 >= 33 && m2 >= 33 && m3 >= 33 && m4 >= 33 && m5 >=
33)
printf("Result: PASS\n");
else
printf("Result: FAIL\n");
return 0;
}
21. Write a C program to sort an array using Bubble sort and display
array after each pass.
#include <stdio.h>
int main() {
int a[50];
int n, i, j, temp;
printf("How many elements? ");
scanf("%d", &n);
printf("Enter %d integers:\n", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1 - i; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
printf("Array after pass %d: ", i + 1);
for (j = 0; j < n; j++)
printf("%d ", a[j]);
printf("\n");
printf("Sorted array (Bubble): ");
for (i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
22. Write a C program to sort an array using Selection sort and count
total swaps.
#include <stdio.h>
int main() {
int a[50];
int n, i, j, minIndex, temp;
int swaps = 0;
printf("How many elements? ");
scanf("%d", &n);
printf("Enter %d integers:\n", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n - 1; i++) {
minIndex = i;
for (j = i + 1; j < n; j++) {
if (a[j] < a[minIndex])
minIndex = j;
if (minIndex != i) {
temp = a[i];
a[i] = a[minIndex];
a[minIndex] = temp;
swaps++;
printf("Sorted array (Selection): ");
for (i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\nTotal swaps = %d\n", swaps);
return 0;
}
23. Write a C program to sort an array using Insertion sort and show
insertion steps.
#include <stdio.h>
int main() {
int a[50];
int n, i, j, key, pass = 0;
printf("How many elements? ");
scanf("%d", &n);
printf("Enter %d integers:\n", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 1; i < n; i++) {
key = a[i];
j = i - 1;
while (j >= 0 && a[j] > key) {
a[j + 1] = a[j];
j--;
a[j + 1] = key;
pass++;
printf("Array after pass %d: ", pass);
for (j = 0; j < n; j++)
printf("%d ", a[j]);
printf("\n");
printf("Sorted array (Insertion): ");
for (i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
24. Write a program in C to implement linear search using arrays.
#include <stdio.h>
int main() {
int a[50];
int n, i, key;
int found = 0;
printf("How many elements? ");
scanf("%d", &n);
printf("Enter %d integers (array must be unsorted or sorted, any):\n", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("Enter element to search: ");
scanf("%d", &key);
for (i = 0; i < n; i++) {
if (a[i] == key) {
printf("Element found at position %d (index %d)\n", i + 1, i);
found = 1;
break; }
if (!found)
printf("Element not found in array.\n");
return 0;
25. Write a program in C to implement binary search using arrays.
#include <stdio.h>
int main() {
int a[50];
int n, i, key;
int low, high, mid;
int found = 0;
printf("How many elements? ");
scanf("%d", &n);
printf("Enter %d integers in ascending order:\n", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("Enter element to search: ");
scanf("%d", &key);
low = 0;
high = n - 1;
while (low <= high) {
mid = (low + high) / 2;
if (a[mid] == key) {
printf("Element found at position %d (index %d)\n", mid + 1,
mid);
found = 1;
break;
} else if (key < a[mid]) {
high = mid - 1;
} else {
low = mid + 1;
if (!found)
printf("Element not found in array.\n");
return 0;