C Program to Print Largest String Among Two Strings

In this program, you'll learn how to print the largest string among two strings. First we find the length of both strings, then check which string length is greater, finally we will get the larger string. The strlen() is the C library function which is used to calculate the length of a given string. The function definition of strlen() is: size_t strlen(const char *str)

Source Code

void main()
    char str1[20],str2[20];
    int len_a,len_b;
    printf("Enter first string: ");
    scanf("%s", str1);
    printf("Enter second string: ");
    scanf("%s", str2);
    len_a = strlen(str1);
    len_b = strlen(str2);
    if(len_a > len_b)
        printf("\nThe larger string is: %s", str1);
        printf("\nThe larger string is: %s", str2);
    return 0;
Enter first string: denis
Enter second string: balaguruswamy

The larger string is: balaguruswamy

"Coding Hub - Learn to code" app now available on Google Play Store