Category Archives: Basic C Programs C Source Code

C Program Display and Count Odd Numbers in Array

C Program Display and Count Odd Numbers in Array /* C Program to display and count all odd numbers in array www.EasyCodeBook.com */ #include <stdio.h> int main() { int array[100],i,n, count=0; printf(“Enter number of elements in array = “); scanf(“%d”, &n); printf(“Enter %d numbers in array\n”, n); for (i = 0; i < n; i++)… Read More »

C Program Find Sum of Even Numbers in Array

C Program Find Sum of Even Numbers in Array /* C Program to Find Sum of Even numbers in array www.EasyCodeBook.com */ #include <stdio.h> int main() { int array[100],i,n, sum=0; printf(“Enter number of elements in array = “); scanf(“%d”, &n); printf(“Enter %d numbers in array\n”, n); for (i = 0; i < n; i++) {… Read More »

C Program Count Frequency of Each Element in Array

C Program Count Frequency of Each Element in Array This C Program will Find Number of Occurences of Every Element in Array. /* C Program to Count frequencies of each element of an array of numbers www.EasyCodeBook.com */ #include <stdio.h> int main() { int array[100], array2[100], n, i, j, element, count;; printf(“Enter number of elements… Read More »

C Program Sum of Main Diagonal of Square Matrix

C Program Sum of Main Diagonal of Square Matrix   /* Write a C program to input a Square matrix of m rows and m columns and displaying the sum of the main diagonal elements from top left corner to right bottom corner. www.easycodebook.com */ #include <stdio.h> int main() { int sqmatrix[10][10]; int i,j,m,sum=0; printf(“The… Read More »

C Program Matrix Input Output

C Program Matrix Input Output /* Write a C program to input a m x n matrix and displaying in matrix format www.easycodebook.com */ #include <stdio.h> int main() { int matrix[10][10]; int i,j,m,n; printf(“Enter number of Rows [10 Maximum]:”); scanf(“%d”,&m); printf(“Enter number of Columns [10 Maximum:]:”); scanf(“%d”,&n); printf(“\nEnter %d matrix elements in %d x %d… Read More »

C Program Binary to Decimal Number

C Program Binary to Decimal Number Converter   /* Write a C program to input a binary number, and convert into correspondin Decimal number www.easycodebook.com */ #include<stdio.h> #include<math.h> int main() { long int binNum,rem,n,i,decimal; printf(“Enter a Binary Number:”); scanf(“%ld”,&binNum); i=0; decimal=0; for(n=binNum;n!=0;n=n/10) { rem=n%10; decimal=decimal+rem*pow(2,i); i++; } printf(“Decimal Number:%ld “,decimal); return 0; } Output 1:… Read More »

C Program Find Larger Value between Two variables

C Program Find Larger Value between Two variables /* Find larger value between two variable www.easycodebook.com */ #include<stdio.h> int main() { int n1,n2; printf(“Enter value of N1: “); scanf(“%d”,&n1); printf(“Enter value of N2: “); scanf(“%d”,&n2); if(n1>n2) printf(“N1 is larger”); else if(n2>n1) printf(“N2 is larger”); else printf(“Both numbers are equal”); return 0; } Output 1: Enter… Read More »

C Program Find Teranspose Matrix

C Program Find Teranspose Matrix   /* C program to find Transpose of a Matrix www.easycodebook.com */ #include <stdio.h> int main() { int m, n, i, j, matrix1[10][10], transpose[10][10]; printf(“Enter the number of rows and columns of the matrix[Maximum 10]:\n”); scanf(“%d%d”, &m, &n); printf(“Please Enter %d elements Row wise in (%d rows x %d columns)… Read More »

C Program Subtract Two Matrices

C Program Subtract Two Matrices /* C program to subtract two matrices www.easycodebook.com */ #include <stdio.h> int main() { int m, n, i, j, matrix1[10][10], matrix2[10][10], subtraction[10][10]; printf(“Enter the number of rows and columns of matrix\n”); scanf(“%d%d”, &m, &n); printf(“Please Enter %d elements of first matrix\n”,m*n); for (i = 0; i < m; i++) for… Read More »