Computer Science, asked by surendra55922, 11 months ago

write a program to check that entered charcter is viwel character (a,e,i,o,u) or not​

Answers

Answered by Anonymous
0

Answer

Gujjar hereThis program allows the user to enter any character and check whether the user-specified character is Vowel or Consonant using If Else Statement.

// C Program to Check Vowel or Consonant

#include <stdio.h>

int main()

{

   char ch;

   printf("Please Enter an alphabet: \n");

   scanf(" %c", &ch);

   

   if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||

 ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')  {

 printf("\n %c is a VOWEL.", ch);

}

   else {

    printf("\n %c is a CONSONANT.", ch);

}

   return 0;

}

OUTPUT

C Program to Check Vowel or Consonant 1

ANALYSIS

The following statement will ask the user to enter any character, and then we are assigning the character to previously declared variable ch

printf("Please Enter an alphabet: \n");

scanf(" %c", &ch);

Next, we used the If Else Statement to check whether the user entered character is equal to a, e, i, o, u, A, E, I, I, O. And if it is TRUE, it is a Vowel otherwise, it’s a Consonant.

Remember, you can convert all the characters to one case using strlwr or strupr and then check for lowercase or uppercase elements in the If condition

if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||

   ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')  {

printf("\n %c is a VOWEL.", ch);

}

C Program to Check whether a Character is Vowel or Consonant – Approach 2

This program to Check Vowel or Consonant is same as an above program, but we arranged the code more readable

// C Program to Check Whether a Character is Vowel or Consonant

#include <stdio.h>

int main()

{

   char ch;

   int lowercase_Vowel, uppercase_Vowel;

   printf("Please Enter an alphabet: \n");

   scanf(" %c", &ch);

   lowercase_Vowel = (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');

   uppercase_Vowel = (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U');

   if (lowercase_Vowel || uppercase_Vowel) {

    printf("\n %c is a VOWEL.", ch);

}

   else {

    printf("\n %c is a CONSONANT.", ch);

}

   return 0;

}

OUTPUT

C Program to Check Vowel or Consonant 2

OUTPUT 2: Let us enter the Consonant value

C Program to Check Vowel or Consonant 3

C Program to find Vowel or Consonant using Functions

This C program allows the user to enter any character, and find whether the user-specified character is Vowel or Consonant using Functions.

// C Program to Check Whether an Alphabet is Vowel or Consonant

#include <stdio.h>

int check_vowel(char a);

int main()

{

   char ch;

   printf("Please Enter an alphabet: \n");

   scanf(" %c", &ch);

   

   if(check_vowel(ch))  {

 printf("\n %c is a VOWEL.", ch);

}

   else {

    printf("\n %c is a CONSONANT.", ch);

}

   return 0;

}

int check_vowel(char c)

{

   if (c >= 'A' && c <= 'Z')

      c = c + 32;  

 

   if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')

      return 1;

 

   return 0;

}

OUTPUT

C Program to Check Vowel or Consonant 4

OUTPUT 2: Let us enter the Consonant value

C Program to Check Vowel or Consonant 5

C Program to Check Vowel or Consonant using ASCII Values

This C program allows the user to enter any character. Next, it will check whether the specified character is Vowel or Consonant using ASCII Values.

// C Program to Check Whether it is Vowel or Consonant

#include <stdio.h>

 

int main()

{

   char ch;

 

   printf("Please Enter an alphabet: \n");

   scanf(" %c", &ch);

 

   if(ch == 97 || ch == 101 || ch == 105 || ch == 111 || ch == 117 ||  

ch == 65 || ch == 69 || ch == 73 || ch == 79 || ch == 85)

   {

    printf("%c is a VOWEL.\n", ch);

   }

   else if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))

   {

       printf("%c is a CONSONANT.\n", ch);

   }

 

   return 0;

}

OUTPUT

C Program to Check Vowel or Consonant 6

OUTPUT 2: Let us enter the Consonant value

C Program to Check Vowel or Consonant 7

Placed Under: C Programming, C Programs

Radhe Radhe Ji

Answered by Anonymous
0

Answer:

The program is being written in JAVA programming language.

Explanation:

import java.util.*;

class Check

{

public static void main ( String args[ ])

{

Scanner sc = new Scanner( System.in);

System.out.println( "Enter a character");

char ch = sc.nextcharAt(0);

if( ch == a)

{

System.out.println( "Entered character is a");

}

else if( ch == e)

{

System.out.println( "Entered character is e");

}

else if( ch == i)

{

System.out.println( "Entered character is i");

}

else if( ch == o)

{

System.out.println( "Entered character is o");

}

else if( ch == u)

{

System.out.println( "Entered character is u");

}

else

{

System.out.println( "Entered character is invalid");

}

}

}

Similar questions