Write a C programme to print greatest among 3 numbers #include <stdio.h> void main() { int a, b, c; printf("Enter three numbers: "); scanf("%d %d %d", &a, &b, &c); if(a > b) { if(a > c) { printf("a is big"); } else { printf("c is big"); } } else { if(b > c) { printf("b is big"); } else { printf("c is big"); } } } 4. !’ Prime number or not Generated with https://kome.ai #include <stdio.h> void main() { int n, i, count = 0; printf("Enter any number: "); scanf("%d", &n); for(i = 1; i <= n; i++) { if(n % i == 0) { count++; } } if(count == 2) { printf("%d is prime\n", n); } else { printf("%d is not prime\n", n); } } 15. !’ Write a C programme to check the given number is palindrome number or not. #include <stdio.h> void main() { int num, rem, rev = 0, temp; num = 156; // example number temp = num; Generated with https://kome.ai while(num > 0) { rem = num % 10; rev = rev * 10 + rem; num = num / 10; } printf("rev = %d", rev); if(rev == temp) { printf("palindrome"); } else { printf("not a palindrome"); } } 13. !’ Write a C programme to find the factorial of a given number #include <stdio.h> void main() { int i, n, fact = 1; printf("Enter any number: "); scanf("%d", &n); for(i = 1; i <= n; i++) { fact = fact * i; } printf("Factorial = %d", fact); Generated with https://kome.ai } 5. a) Write a C programme to generate all Fibonacci numbers. Logic: The 1st & 2nd terms in the sequence are 0 and 1. Subsequent terms are formed by adding the preceding terms. #include <stdio.h> int main() { int n1 = 0, n2 = 1, n3, i, number; printf("Enter the number of elements: "); scanf("%d", &number); printf("%d %d ", n1, n2); for(i = 2; i < number; i++) { n3 = n1 + n2; printf("%d ", n3); n1 = n2; n2 = n3; } return 0; } 2. !’ Write a C programme to add two matrices Generated with https://kome.ai #include <stdio.h> void main() { int a[3][3], b[3][3], c[3][3], i, j; printf("Enter first array elements:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &a[i][j]); } } printf("Enter second array elements:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &b[i][j]); } } // Matrix addition for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { c[i][j] = a[i][j] + b[i][j]; } } printf("The addition of two matrices is:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d ", c[i][j]); } printf("\n"); } Generated with https://kome.ai } 11. Bubble sort #include <stdio.h> void main() { int a[50], n, i, j, temp; printf("Enter the size of array: "); scanf("%d", &n); printf("Enter the array elements: "); for(i = 0; i < n; i++) scanf("%d", &a[i]); for(i = 1; i < n; i++) for(j = 0; j < (n - i); j++) if(a[j] > a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } printf("Array after sorting: "); for(i = 0; i < n; i++) printf("%d ", a[i]); } 12. Selection sort Generated with https://kome.ai #include <stdio.h> int main() { int a[10], i, j, n, maxi, temp; printf("Enter n value: "); scanf("%d", &n); printf("Enter %d elements into array\n", n); for(i = 0; i < n; i++) scanf("%d", &a[i]); for(i = 0; i < n; i++) { maxi = i; for(j = i + 1; j < n; j++) { if(a[maxi] < a[j]) maxi = j; } temp = a[maxi]; a[maxi] = a[i]; a[i] = temp; } printf("Sorted array\n"); for(i = 0; i < n; i++) printf("%3d", a[i]); return 0; } Addition of 2 matrix... #include <stdio.h> Generated with https://kome.ai void read(int p[10][10], int m, int n); void madd(int first[10][10], int second[10][10], int m, int n); int main() { int m, n; int first[10][10], second[10][10]; printf("Enter the number of rows and columns of matrix\n"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix\n"); read(first, m, n); printf("Enter the elements of second matrix\n"); read(second, m, n); printf("Sum of entered matrices:-\n"); madd(first, second, m, n); return 0; } void read(int p[10][10], int m, int n) { int i, j; for(i = 0; i < m; i++) for(j = 0; j < n; j++) scanf("%d", &p[i][j]); } void madd(int first[10][10], int second[10][10], int m, int n) { int i, j, sum[10][10]; for(i = 0; i < m; i++) { for(j = 0; j < n; j++) { sum[i][j] = first[i][j] + second[i][j]; printf("%d\t", sum[i][j]); } Generated with https://kome.ai printf("\n"); } } Multiplication of matrix #include <stdio.h> void read(int p[10][10], int m, int n); void Matrixmult(int first[10][10], int second[10][10], int multiply[10][10], int m, int n, int p, int q); int main() { int m, n, p, q, c, d; int first[10][10], second[10][10], multiply[10][10]; printf("Enter number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("Enter elements of first matrix\n"); read(first, m, n); printf("Enter number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q); read(second, p, q); if(n != p) printf("The matrices can't be multiplied with each other.\n"); else { Matrixmult(first, second, multiply, m, n, p, q); printf("Product of the matrices:\n"); for(c = 0; c < m; c++) { for(d = 0; d < q; d++) Generated with https://kome.ai printf("%d\t", multiply[c][d]); printf("\n"); } } return 0; } void read(int p[10][10], int m, int n) { int i, j; for(i = 0; i < m; i++) for(j = 0; j < n; j++) scanf("%d", &p[i][j]); } void Matrixmult(int first[10][10], int second[10][10], int multiply[10][10], int m, int n, int p, int q) { int c, d, k, sum; for(c = 0; c < m; c++) { for(d = 0; d < q; d++) { sum = 0; for(k = 0; k < p; k++) sum += first[c][k] * second[k][d]; multiply[c][d] = sum; } } } Write a C programme to check whether the given string is palindrome or not Generated with https://kome.ai #include <stdio.h> #include <string.h> void main() { char a[100]; int low = 0, high, flag = 0; printf("Enter any string: "); scanf("%s", a); high = strlen(a) - 1; while(low < high) { if(a[low] != a[high]) { flag = 1; break; } low++; high--; } if(flag == 0) printf("palindrome"); else printf("not a palindrome"); } Write a C program that uses non-recursive function to search for a key value in a given list of integers using linear search method void linearsearch(int a[], int n, int se); #include <stdio.h> int main() { Generated with https://kome.ai int a[20], n, se, i; printf("Enter n value: "); scanf("%d", &n); printf("Enter %d elements into array:\n", n); for(i = 0; i < n; i++) scanf("%d", &a[i]); printf("Enter search element: "); scanf("%d", &se); linearsearch(a, n, se); return 0; } void linearsearch(int a[], int n, int se) { int i, check = 0; for(i = 0; i < n; i++) { if(se == a[i]) { check = 1; break; } } if(check == 1) printf("element present"); else printf("element not present"); return; } Generated with https://kome.ai Write a C program that uses non-recursive function to search for a key value in a given sorted list of integers using binary search method #include <stdio.h> #define MAX_SIZE 5 void binary_search(int arr[], int element); int main() { int arr[MAX_SIZE], i, element; printf("Simple Binary Search Example - Array and Functions\n"); printf("\nEnter %d Elements for Searching : \n", MAX_SIZE); for(i = 0; i < MAX_SIZE; i++) scanf("%d", &arr[i]); printf("Enter Element to Search : "); scanf("%d", &element); binary_search(arr, element); return 0; } void binary_search(int arr[], int element) { int f = 0, r = MAX_SIZE - 1, mid; while(f <= r) { mid = (f + r) / 2; if(arr[mid] == element) { printf("\nSearch Element : %d : Found : Position : %d\n", element, mid + 1); break; } else if(arr[mid] < element) Generated with https://kome.ai f = mid + 1; else r = mid - 1; } if(f > r) printf("\nSearch Element : %d : Not Found\n", element); } Generated with https://kome.ai