// Assignment Final Question 4
//
// Name: <Maribel Fuentes>
//
// Class: C Programming, <Fall 2024>
//
// Date: <December 2, 2024>
#include <stdio.h>
#include <ctype.h>
// Function to check if a word is legal
int isLegal(char theString[]) {
// Define the vowels including 'y'
char vowels[] = "aeiouyAEIOUY";
int i, j;
// Iterate through each character in the string
for (i = 0; theString[i] != '\0'; i++) {
// Check if the character is a vowel
for (j = 0; vowels[j] != '\0'; j++) {
if (theString[i] == vowels[j]) {
return 1; // Legal word (contains at least one vowel)
}
}
}
return 0; // Illegal word (contains no vowels)
}
int main() {
char word1[] = "sch";
char word2[] = "apple";
char word3[] = "APPle";
char word4[] = "try";
printf("Word: %s - %s\n", word1
, isLegal
(word1
) ? "Legal" : "Illegal"); printf("Word: %s - %s\n", word2
, isLegal
(word2
) ? "Legal" : "Illegal"); printf("Word: %s - %s\n", word3
, isLegal
(word3
) ? "Legal" : "Illegal"); printf("Word: %s - %s\n", word4
, isLegal
(word4
) ? "Legal" : "Illegal");
return 0;
}
Ly8gQXNzaWdubWVudCBGaW5hbCBRdWVzdGlvbiA0Ci8vCi8vIE5hbWU6IDxNYXJpYmVsIEZ1ZW50ZXM+Ci8vCi8vIENsYXNzOiBDIFByb2dyYW1taW5nLCA8RmFsbCAyMDI0PgovLwovLyBEYXRlOiA8RGVjZW1iZXIgMiwgMjAyND4KCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8Y3R5cGUuaD4KCi8vIEZ1bmN0aW9uIHRvIGNoZWNrIGlmIGEgd29yZCBpcyBsZWdhbAppbnQgaXNMZWdhbChjaGFyIHRoZVN0cmluZ1tdKSB7CiAgICAvLyBEZWZpbmUgdGhlIHZvd2VscyBpbmNsdWRpbmcgJ3knCiAgICBjaGFyIHZvd2Vsc1tdID0gImFlaW91eUFFSU9VWSI7CiAgICBpbnQgaSwgajsKCiAgICAvLyBJdGVyYXRlIHRocm91Z2ggZWFjaCBjaGFyYWN0ZXIgaW4gdGhlIHN0cmluZwogICAgZm9yICh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