fork download
  1. // Assignment Question 4 Final Exam
  2. //
  3. // Name: <Tasos Paloukos>
  4. //
  5. // Class: C Programming, <Fall 2024>
  6. //
  7. // Date: <December 11, 2024>
  8.  
  9. #include <stdio.h>
  10. #include <ctype.h>
  11.  
  12. // Function to check if a word is legal
  13. int isLegal(char theString[]) {
  14. // Define the vowels including 'y'
  15. char vowels[] = "aeiouyAEIOUY";
  16. int i, j;
  17.  
  18. // Iterate through each character in the string
  19. for (i = 0; theString[i] != '\0'; i++) {
  20. // Check if the character is a vowel
  21. for (j = 0; vowels[j] != '\0'; j++) {
  22. if (theString[i] == vowels[j]) {
  23. return 1; // Legal word (contains at least one vowel)
  24. }
  25. }
  26. }
  27.  
  28. return 0; // Illegal word (contains no vowels)
  29. }
  30.  
  31. int main() {
  32. char word1[] = "sch";
  33. char word2[] = "apple";
  34. char word3[] = "APPle";
  35. char word4[] = "try";
  36.  
  37. printf("Word: %s - %s\n", word1, isLegal(word1) ? "Legal" : "Illegal");
  38. printf("Word: %s - %s\n", word2, isLegal(word2) ? "Legal" : "Illegal");
  39. printf("Word: %s - %s\n", word3, isLegal(word3) ? "Legal" : "Illegal");
  40. printf("Word: %s - %s\n", word4, isLegal(word4) ? "Legal" : "Illegal");
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Word: sch - Illegal
Word: apple - Legal
Word: APPle - Legal
Word: try - Legal