In: Computer Science
Translate this algorithm to code on C
compare(char array[ ])
word = split(array, " "); //gets the first word before the blank space
if word == Hello {
print("I am saying hello");
}else if (word == Bye)
print("I am saying goodbye");
}
Example---------------------
char array = "Hello Ana";
compare(array);
char array1 = "Bye Ana"
compare(array1);
result
"I am saying hello"
"I am saying goodbye"
#include<stdio.h>
void compare(char arra[ ])
{
if(strlen(arra) >= 3)
{
if(strlen(arra) >= 5 && arra[0] == 'H' &&
arra[1] == 'e' && arra[2] == 'l' && arra[3] == 'l'
&& arra[4] == 'o')
printf("I am saying hello");
if(arra[0] == 'B' && arra[1] == 'y' && arra[2] ==
'e')
printf("I am saying goodbye");
}
}
int main() {
compare("Hello Ana");
printf("\n");
compare("Bye Ana");
}
// Hit the thumbs up if you are fine with the answer. Happy Learning!