#include #include #include
int main() {
char letter;
clrscr(); // Clears the screen in Turbo C
printf("Enter a letter: ");
scanf("%c", &letter);
letter = tolower(letter); // Convert to lowercase for easier comparison
if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') {
printf("%c is a vowel.\n", letter);
} else if (isalpha(letter)) { // Check if it's a letter
printf("%c is a consonant.\n", letter);
} else {
printf("%c is not a letter.\n", letter);
}
getch(); // Pauses the program until a key is pressed
return 0;
}
```
Explanation:
1. Include Headers:
- `stdio.h`: Standard input/output library (for `printf` and `scanf`).
- `conio.h`: Console input/output library (for `clrscr` and `getch`).
- `ctype.h`: Character type library (for `tolower` and `isalpha`).
2. Clear Screen:
- `clrscr();`: Clears the screen, giving a cleaner output.
3. Get Input:
- `printf("Enter a letter: ");`: Prompts the user to enter a letter.
- `scanf("%c", &letter);`: Reads the character input and stores it in the `letter` variable.
4. Convert to Lowercase:
- `letter = tolower(letter);`: Converts the entered letter to lowercase, making the comparison case-insensitive.
5. Check for Vowel or Consonant:
- `if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u')`: Checks if the letter is one of the vowels. If yes, prints that it is a vowel.
- `else if (isalpha(letter))`: Checks if the entered character is a letter using `isalpha()`. If yes, it is a consonant, so it prints that it is a consonant.
- `else`: If the character is not a letter, it prints a message saying it's not a letter.
6. Pause the Program:
- `getch();`: This waits for the user to press a key before the program ends. This is common in Turbo C to see the output clearly before the program closes.
How to Compile and Run in Turbo C:
1. Create a File: Save the code above as a `.c` file (e.g., `vowel_consonant.c`).
2. Open Turbo C: Launch the Turbo C IDE.
3. Compile: Press `Alt+F9` or go to `Compile` -> `Compile` to compile the code.
4. Run: Press `Ctrl+F9` or go to `Run` -> `Run` to execute the program.
Note: Turbo C is an older compiler, and it's generally recommended to use modern compilers like GCC (in Linux/macOS) or Visual Studio (in Windows). However, if you're using Turbo C for educational purposes or compatibility, this code will work correctly.