(Please answer in C PROGRAMMING) Print the two strings in alphabetical order. As
ID: 3677758 • Letter: #
Question
(Please answer in C PROGRAMMING) Print the two strings in alphabetical order. Assume the strings are lowercase. End with newline. Sample output: capes rabbits
#include #include int main(void)
{ char firstString[50]; char secondString[50]; strcpy(firstString, "rabbits"); strcpy(secondString, "capes");
/* Your solution goes here */ return 0; }
Here is my sample work:
#include
#include
Int main (void)
{
char firstString[50];
char secondString[50];
strcpy(firstString, “rabbits”);
strcpy(secondString, “capes”);
if (strcmp(secondString, firstString) >0)
{
Printf(“%s rabbits ”, firstString);
}
Else
{
Printf(“capes %s ”, firstString);
}
Return 0;
}
RUNS:
Testing input rabbits capes
Your output: capes rabbits
Testing input capes rabbits
Your output: capes rabbits
Testing input clearly clear
Expected output: clear clearly
Your output: capes clearly
Explanation / Answer
code:
#include <stdio.h>
#include <string.h>
int main()
{
char firstString[50];
char secondString[50];
//strcpy(firstString, "rabbits");
//strcpy(secondString, "capes");
printf("enter the first string");
scanf("%s",firstString);
printf("enter the second string");
scanf("%s",secondString);
if(strcmp(firstString,secondString)>0) //second string is alphabatically smaller
{
printf("%s %s ", secondString,firstString);
}
else
{
printf("%s %s ", firstString,secondString);
}
return 0;
}
Sample Input: enter the first string: manu
enter the second string: nanu
Sample output: manu nanu
if you have any doubt then ask
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.