This is Program C. question Write a complete program using two arrays, upper and
ID: 3764050 • Letter: T
Question
This is Program C. question
Write a complete program using two arrays, upper and lower to keep the upper
And lower alphabet respectively.
Ask the user to enter string example:
This is a test from Jupiter. Soon you will see who is from Jupiter!!! May be Dr. D.
Your program should parse the string and keep track of number of alphabet. Both arrays are indexed from 0 to 25. The logical way to do this is to use upper[0] to
Count the number of ‘A’, and upper[1] to count number of ‘B’ and so on. Likewise
For the lower array.
Output should look like:
A: 0 a:2
B: 0 b:1
….
….
Explanation / Answer
#include<stdio.h>
#include<string.h>
int main()
{
int upper[26];
int lower[26];
char str[100];
for(int i=0;i<26;i++)
{
upper[i] = 0;
lower[i] = 0;
}
printf("Input a string : ");
fgets (str, 100, stdin);
int i = 0;
int temp;
while(str[i])
{
temp = str[i];
if(temp>=65 && temp<=90)
{
temp = temp-65;
upper[temp]++;
}
else if(temp>=97 && temp<=122)
{
temp = temp-97;
lower[temp]++;
}
i++;
}
char A,a;
for(int i=0;i<26;i++)
{
A = (char)(i+65);
a = (char)(i+97);
printf("%c : %d %c : %d ",A,upper[i],a,lower[i]);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.