0% found this document useful (0 votes)
57 views

To Check Whether A: Character Is An Alphabet, Digit or Special Character

The document contains code snippets for C programs to check if a character is an alphabet, digit, or special character; check if an alphabet is a vowel or consonant; check the description for a grade; and check the temperature state based on the temperature in Celsius. Each code snippet uses if/else conditional statements within a function to check the input character or number and print the corresponding output.

Uploaded by

F J
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

To Check Whether A: Character Is An Alphabet, Digit or Special Character

The document contains code snippets for C programs to check if a character is an alphabet, digit, or special character; check if an alphabet is a vowel or consonant; check the description for a grade; and check the temperature state based on the temperature in Celsius. Each code snippet uses if/else conditional statements within a function to check the input character or number and print the corresponding output.

Uploaded by

F J
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

to check whether a character is an alphabet, digit or special character.

Input : @
Output : This is a special character.

int grade(char x){


if(isalpha (x)>=1)
printf("Alphabet");
else if(isdigit (x)>=1)
printf("Digit");
else
printf("Special character");
return 0;
}
int main(){
char y;
printf("Enter sign: ");
scanf("%c", &y);
grade(y);
return 0;
}

Write a C program to check whether an alphabet is a vowel or consonant.


Input : k
Output : The alphabet is a consonant.

#include <stdio.h>
#include <stdlib.h>

int grade(char a){


if(a=='a')
printf("vowel");
else if(a=='e')
printf("vowel");
else if(a=='i')
printf("vowel");
else if(a=='o')
printf("vowel");
else if(a=='u')
printf("vowel");
else if(a=='A')
printf("vowel");
else if(a=='E')
printf("vowel");
else if(a=='I')
printf("vowel");
else if(a=='O')
printf("vowel");
else if(a=='U')
printf("vowel");
else
printf("Consonant");
return 0;
}
int main(){
char y;
printf("Enter sign: ");
scanf("%c", &y);
grade(y);
return 0;
}

Write a program in C to accept a grade and declare the equivalent


description :
Grade Description
E Excellent
V Very Good
G Good
A Average
F Fail
Input : Input the grade :A
Output : You have chosen : Average

#include <stdio.h>
#include <stdlib.h>
int grade(char x){
if(x=='E')
printf("Excellent");
else if(x=='V')
printf("Very Good");
else if(x=='G')
printf("Good");
else if(x=='A')
printf("Average");
else if(x=='F')
printf("Fail");
else
printf("Invalid");
return 0;
}
int main(){
char y;
printf("Enter sign: ");
scanf("%c", &y);
grade(y);
return 0;
}

12. Write a C program to read temperature in centigrade and display a suitable


message
according to temperature state below :
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Input : 42
Output : Its very hot.

#include <stdio.h>
#include <stdlib.h>
int grade(int x){
if(x<0)
printf("Freezing weather");
else if(x<=10)
printf("Very Cold weather");
else if(x<=20)
printf("Cold weather");
else if(x<=30)
printf("Normal");
else if(x<=40)
printf("Hot");
else if(x>=40)
printf("Very Hot");
return 0;
}
int main(){
int y;
printf("Enter tempereture: ");
scanf("%d", &y);
grade(y);
return 0;
}

You might also like