Category Archives: Basic C Programs for Beginners

Check Even Odd with Switch Statement

Check Even Odd with Switch Statement – C Program to input a number and check it for even or odd using a switch statement. Source Code #include <stdio.h> int main() { int n; printf(“Enter a number to check for Even/Odd:”); scanf(“%d”,&n); switch(n%2) { case 0: printf(“%d is Even”,n); break; case 1: printf(“%d is Odd”,n); break;… Read More: Check Even Odd with Switch Statement »

Loading

Count Digits in String C Program

Count Digits in String C Program – Input a string containing both digits and alphabets. This program in C language will display the count of digits in the given string. Source Code /* * C program to count the digits present in the given string */ #include <stdio.h> void main() { char str[100]; int i,count=0;… Read More: Count Digits in String C Program »

Loading

Python Heart Shape Star Pattern Program

Python Heart Shape Star Pattern Program This Python pattern printing program uses the logic of the following figure. We can see that how the stars are present in certain positions. We will create some conditions on the basis of star posittion in each row. For example we consider the first row which is zero row.… Read More: Python Heart Shape Star Pattern Program »

Loading

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 Display and Count Odd Numbers in Array »

Loading

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 Find Sum of Even Numbers in Array »

Loading

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 Count Frequency of Each Element in Array »

Loading

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 Sum of Main Diagonal of Square Matrix »

Loading

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 Matrix Input Output »

Loading

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 Binary to Decimal Number »

Loading

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 Larger Value between Two variables »

Loading