Category Archives: Basic C Programs for Beginners

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 »

 2,205 total views,  2 views today

C Program Add Two Matrix

C Program Add Two Matrix /* C program to add two matrices www.easycodebook.com */ #include <stdio.h> int main() { int m, n, i, j, matrix1[10][10], matrix2[10][10], sum[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 »

 1,387 total views,  3 views today

C Program Sort N Strings in Ascending Order

C Program Sort N Strings in Ascending Order /* C program to input n strings and sort them in ascending order alphabetically */ #include <stdio.h> #include <string.h> int main() { char str[30][40],temp[30]; int n,i,j; printf(“\nString Sorting: Sorts N strings:\n”); printf(“************************************\n”); printf(“Input number of strings :”); scanf(“%d”,&n); getchar(); printf(“Input string %d :\n”,n); for(i=0;i<n;i++) gets(str[i]); /*Logic for… Read More »

 3,589 total views,  4 views today

C Program Find Substring Index in String

C Program Find Substring Index in String /* C program to input Source string and a search substring to be searched in first string. And displaying found or not, using string function strstr(). */ #include <stdio.h> #include <string.h> int main() { char str[100]; char search[50]; char *ptr; printf("Enter a string:\n"); gets(str); printf("Enter search substring:\n"); gets(search);… Read More »

 4,559 total views,  12 views today

C Program String Concatenation using strcat

C Program String Concatenation using strcat /* C program to input two strings and concatenating the second string at end of first string using strcat() predefined string function. */ #include <stdio.h> #include <string.h> int main() { char str1[100], str2[100]; printf("Enter the first string\n"); gets(str1); printf("Enter the second string\n"); gets(str2); strcat(str1, str2); printf("String obtained after concatenation\nusing… Read More »

 691 total views

C Program Case Insensitive String Comparison

C Program Case Insensitive String Comparison USING stricmp() built-in string function /* C program to input two strings and check whether both strings are the same (equal) or not using stricmp() predefined function. stricmp() gives a case insensitive comparison. www.easycodebook.com */ #include <stdio.h> #include <string.h> int main() { char str1[100], str2[100]; printf(“Enter first string for… Read More »

 4,386 total views,  12 views today

C Program Compare String using strcmp

C Program Compare String using strcmp /* C program to input two strings and check whether both strings are the same (equal) or not using strcmp() predefined function. strcmp() gives a case sensitive comparison. www.easycodebook.com */ #include <stdio.h> #include <string.h> int main() { char str1[100], str2[100]; printf(“Enter first string\n”); gets(str1); printf(“Enter second string\n”); gets(str2); if… Read More »

 661 total views

C Program String Reverse Using strrev

C Program String Reverse Using strrev /* C Program Reverse a string using strrev() predefined function www.easycodebook.com */ #include <stdio.h> #include <string.h> int main() { char str[100]; printf("Please, Enter a string to reverse\n"); gets(str); strrev(str); printf("The Reverse string is : %s\n", str); return 0; } Output Please, Enter a string to reverse ABCDEF The Reverse… Read More »

 658 total views,  2 views today

C Program String tOGGLE cASE Conversion

Topic:     /*C program to convert given string into tOOGLE cASE.*/ #include <stdio.h> int main() { char str[100]; int i; printf(“Enter a string to change into tOGGLE cASE : “); gets(str); /* toggle each string character if it is upper case, change to lower case if it is lower case, change into upper case*/… Read More »

 691 total views,  1 views today