Write a complete program using two arrays, upper and lower to keep the upper And
ID: 3538980 • Letter: W
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. Soon you will see the future.
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:0
Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
int i,len;
char s[100];
int upper[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lower[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
clrscr();
printf("enter a string ");
gets(s);
len=strlen(s);
for(i=0;i<len;i++)
{
if(isupper(s[i]))
{
upper[s[i]-65]++;}
if(islower(s[i]))
{
lower[s[i]-97]++;}
}
for(i=0;i<26;i++)
{
printf("%c:%d %c:%d ",'A'+i,upper[i],'a'+i,lower[i]);
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.