-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path59A.c
45 lines (36 loc) · 1.11 KB
/
59A.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
38
39
40
41
42
43
44
45
#include <stdio.h>
int main(){
char str[101];
// Input string here
scanf("%s", str);
getchar();
// Scan for lowercase count and uppercase count
int index = 0, upperCount = 0, lowerCount = 0;
while (str[index] != '\0') {
if (str[index] >= 'A' && str[index] <= 'Z') upperCount++;
else lowerCount++;
index++;
}
if (lowerCount >= upperCount) {
// Replacing char algorithm here
index = 0; // Reset index value
while (str[index] != '\0') {
// Assume the selected char is an uppercase, then convert it to lowercase
if (str[index] >= 'A' && str[index] <= 'Z') str[index] += 32;
index++;
}
}
else {
// Replacing char algorithm here
index = 0; // Reset index value
while (str[index] != '\0') {
// Assume the selected char is a lowecase, then convert it to uppercase
if (str[index] >= 'a' && str[index] <= 'z') str[index] -= 32;
index++;
}
}
// Print the output
printf("%s\n", str);
getchar();
return 0;
}