-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ5.c
37 lines (32 loc) · 958 Bytes
/
Q5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
int uppercase = 0, lowercase = 0, digits = 0, others = 0;
printf("Enter a string: ");
// Read characters until newline character is encountered
while ((ch = getchar()) != '\n') {
// Check if the character is uppercase
if (isupper(ch)) {
uppercase++;
}
// Check if the character is lowercase
else if (islower(ch)) {
lowercase++;
}
// Check if the character is a digit
else if (isdigit(ch)) {
digits++;
}
// All other characters
else {
others++;
}
}
// Display appropriate messages
printf("Uppercase characters: %d\n", uppercase);
printf("Lowercase characters: %d\n", lowercase);
printf("Digits: %d\n", digits);
printf("Other characters: %d\n", others);
return 0;
}