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
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    char str1[20],str2[20];
    int len_a,len_b;
    cout<<"Enter first string: ";
    cin>> str1;
    cout<<"Enter second string: ";
    cin>> str2;
    len_a = strlen(str1);
    len_b = strlen(str2);
    if(len_a > len_b)
    {
        cout<< str1;
    }
    else
    {
        cout<< str2;
    }
    return 0;
}
Output
Enter first string: denis
Enter second string: balaguruswamy
The larger string is: balaguruswamy