// Assignment Question 4 Final Exam
//
// Name: <Tasos Paloukos>
//
// Class: C Programming, <Fall 2024>
//
// Date: <December 11, 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;
}
Ly8gQXNzaWdubWVudCBRdWVzdGlvbiA0IEZpbmFsIEV4YW0KLy8KLy8gTmFtZTogPFRhc29zIFBhbG91a29zPgovLwovLyBDbGFzczogQyBQcm9ncmFtbWluZywgPEZhbGwgMjAyND4KLy8KLy8gRGF0ZTogPERlY2VtYmVyIDExLCAyMDI0PgoKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdHlwZS5oPgoKLy8gRnVuY3Rpb24gdG8gY2hlY2sgaWYgYSB3b3JkIGlzIGxlZ2FsCmludCBpc0xlZ2FsKGNoYXIgdGhlU3RyaW5nW10pIHsKICAgIC8vIERlZmluZSB0aGUgdm93ZWxzIGluY2x1ZGluZyAneScKICAgIGNoYXIgdm93ZWxzW10gPSAiYWVpb3V5QUVJT1VZIjsKICAgIGludCBpLCBqOwoKICAgIC8vIEl0ZXJhdGUgdGhyb3VnaCBlYWNoIGNoYXJhY3RlciBpbiB0aGUgc3RyaW5nCiAgICBmb3Ig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