Question 10
Write a program to accept a string and display
(1) The number of lower case characters
(2) The number of uppercase characters
(3) The number of special characters
(4) The number of digits present in the string
Answers
Answered by
0
Explanation:
int main()
{
char str[100];
int i;
int upper=0,lower=0,num=0,special=0;;
printf("Please enter the string \n");
gets(str);
for(i=0; str[i] != '\0'; i++){
//check for uppercase
if(str[i]>='A' && str[i]<='Z') {
upper++;
}else if(str[i]>='a' && str[i]<='z') {//check lower case
lower++;
}else if(str[i]>='1' && str[i]<='9') { //check number
num++;
}
else{
special++;
}
}
printf("\nUpper case letters: %d",upper);
printf("\nLower case letters: %d",lower);
printf("\nNumbers: %d",num);
printf("\nSpecial characters: %d",special);
getch();
return 0;
}
Similar questions
Business Studies,
1 month ago
Science,
1 month ago
Math,
1 month ago
Hindi,
2 months ago
Environmental Sciences,
2 months ago
Math,
10 months ago
Biology,
10 months ago