Write a program to check the character is an alphabet or not.
Example:
Input: ch = 'a' Output: a is an alphabet
Approach
C
#include <stdio.h>int main(){char ch;printf("Enter a character: ");scanf("%c", &ch);if ((ch >= 'a' && ch <= 'z' )|| (ch >= 'A' && ch <= 'Z')){printf("%c is an alphabet ", ch);}else{printf("%c is not an alphabet ", ch);}return 0;}
Java
import java.util.Scanner;public class ISAlphabet {public static void main(String[] args) {System.out.println("Enter a character: ");Scanner sc = new Scanner(System.in);char ch = sc.nextLine().charAt(0);if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {System.out.printf("%c is an alphabet ", ch);} else {System.out.printf("%c is not an alphabet ", ch);}sc.close();}}
No comments:
Post a Comment