C program to check whether the input is uppercase or lowercase or a digit or a special symbol
Answers
int main()
{
//1
char inputString[100];
int upperCount,lowerCount,specialCount,digitCount,i;
//2
printf("Enter a String : ");
gets(inputString);
//3
printf("String input is %s ",inputString);
//4
upperCount = lowerCount = specialCount = digitCount = 0;
//5
for(i =0; inputString[i]!= '\0'; i++){
//6
if(inputString[i] >= 'A' && inputString[i] <= 'Z'){ upperCount ++; }else if(inputString[i] >= 'a' && inputString[i] <= 'z'){ lowerCount ++; }else if(inputString[i] >= '0' && inputString[i] <= '9'){
digitCount ++;
}else{
specialCount ++;
}
}
//7
printf("\nUpper case count : %d \n",upperCount);
printf("Lower case count : %d \n",lowerCount);
printf("Digit count : %d \n",digitCount);
printf("Special character count : %d \n",specialCount);
return 0;
}
The following codes will have to be typed in script mode, saved and then executed.
CODE:
x = input("Enter a character:")
if ord(x) >= 65 and ord(x) <= 90:
print(x, "is an UPPERCase character.")
elif ord(x) >= 97 and ord(x) <= 122:
print(x, "is a LOWERCase character.")
elif ord(x) >= 48 and ord(x) <= 57:
print(x, "is a number.")
else:
print(x, "is a special character.")
OUTPUT: