Set 1:Q1-Q5 Set 2:Q6-Q10 Set 3:Q11-Q15
Question:6
WAP to take input for a character check and print whether the character is an upper case alphabet or not?(Using only single line)
Sol:
#include <stdio.h> int main() { char ch; printf("Enter any character "); scanf("%c",&ch); (ch>='A' && ch<='Z')?printf("It is an upper case alphabet"):printf("It is not an upper case alphabet"); return 0; }
Output:
case 1:
Enter any character d
It is not an upper case alphabetcase :2
Enter any character E
It is an upper case alphabet
Question: 7
WAP to take input for a character check and print whether the character is a lower case alphabet or not?(Using only single line)
Sol:
#include <stdio.h> int main() { char ch; printf("Enter any character "); scanf("%c",&ch); (ch>='a' && ch<='z')?printf("It is a lower case alphabet"):printf("It is not a lower case alphabet"); return 0; }
Output:
case 1:
Enter any character d
It is a lower case alphabetcase :2
Enter any character H
It is not a lower case alphabet
Question: 8
WAP to take input for a character check and print whether the character is a digit or not?(Using only single line)
Sol:
#include <stdio.h> int main() { char ch; printf("Enter any character "); scanf("%c",&ch); (ch>='0' && ch<='9')?printf("It is a digit"):printf("It is not a digit"); return 0; }
Output:
case 1:
Enter any character 6
It is a digitcase :2
Enter any character d
It is not a digit
Question: 9
WAP to take input for a character check and print whether the character is a vowel or not?(Using only single line)
Sol:
#include <stdio.h> int main() { char ch; printf("Enter any character "); scanf("%c",&ch); (ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' || ch=='O' || ch=='o' || ch=='U' || ch=='u')?printf("It is a vowel"):printf("It is not a vowel"); return 0; }
Output:
case 1:
Enter any character e
It is a vowelcase :2
Enter any character w
It is not a vowel
Question: 10
Write a C program to take input for a character, check and print whether the character is an alphabet, digit or a special character?
Sol:
#include <stdio.h> int main() { char ch; printf("Enter any character "); scanf("%c",&ch); if((ch>='A' && ch<='Z')|| (ch>='a' && ch<='z')) printf("It is an alphabet"); else if(ch>='0' && ch<='9') printf("it is a digit"); else printf("it is a special character"); return 0; }
Output:
case 1:
Enter any character 4
it is a digitcase 2:
Enter any character w
It is an alphabetcase 3:
Enter any character #
it is a special character