Write a program that reads an input line from the user (until the new-line chara
ID: 3536425 • Letter: W
Question
Write a program that reads an input line from the user (until the new-line character ) and
displays the number of times each lower-case letter appears in it (Everything else in the input
except lower-case letters can be ignored.)
For example:
Please input a line in lower-case: hello, world!
The letter %u2019d%u2019 appears 1 time(s).
The letter %u2019e%u2019 appears 1 time(s).
The letter %u2019h%u2019 appears 1 time(s).
The letter %u2019l%u2019 appears 3 time(s).
The letter %u2019o%u2019 appears 2 time(s).
The letter %u2019r%u2019 appears 1 time(s).
The letter %u2019w%u2019 appears 1 time(s).
Explanation / Answer
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
void main()
{
char a[100],b;
int tot=0,i;
cout<<"enter stringc";
gets(a);
int len;
len=strlen(a);
for(i=0;i<len;i++)
{
tot=0;
b=a[i];
for(int j=0;j<len;j++)
{
if(b==a[j])
tot++;
}
cout<<" theletter "<<a[i]<<" occur "<<tot<<" times";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.