C Language Given String Variables Name1 Name2 Write Fragment Code Assigns Larger Two Varia Q37114106

In C language:

Given the string variables name1 and name2, write a fragment ofcode that assigns the larger of the two to the variable first(assume all three are already declared and name1 and name2 assignedvalues ).


Answer


// assuming all three are already declared and name1 and name2 are assigned valuesif (strlen(name1) > strlen(name2)) { strcpy(first, name1);} else { strcpy(first, name2);}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.