Program for multiplication of two matrices

#include <stdio.h> int main() { int a[10][10], b[10][10], result[10][10]; int i, j, k, r1, c1, r2, c2; // Input rows and columns for first matrix printf(“Enter rows and columns for first matrix: “); scanf(“%d %d”, &r1, &c1); // Input rows and columns for second matrix printf(“Enter rows and columns for second matrix: “); scanf(“%d %d”, […]

C Program to Print the Alternate Elements in an Array

#include <stdio.h> int main() { int arr[100], n, i; // Accept number of elements printf(“Enter the number of elements: “); scanf(“%d”, &n); // Accept array elements printf(“Enter %d elements:\n”, n); for (i = 0; i < n; i++) { scanf(“%d”, &arr[i]); } // Print alternate elements (0th, 2nd, 4th, …) printf(“Alternate elements in the array:\n”); […]

Write a program to find GCD of two numbers

The GCD or HCF (Highest Common Factor) of two integers is the greatest integer that divides both the integers with remainder equals to zero. This can be illustrated by Euclid’s remainder Algorithm which states that GCD of two numbers say x and y i.e. GCD(x, y) = x if y is 0 = GCD(y, x%y) […]

Write a program using recursion to find power of a number

We can write, nm = n*nm-1 =n*n*nm-2 =n*n*n*……………m times *nm-m The program which implements the above logic is as follows: #include<stdio.h> int power(int,int); void main() { int n,m,k; printf(“Enter the value of n and m”); scanf(“%d%d”,&n,&m); k=power(n,m); printf(“The value of nm for n=%d and m=%d is %d”,n,m,k); } int power(int x, int y) { if(y==0) […]