Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated”
For example: If the phrase is “full proof” then the output will
be:
Number of characters repeated: 3
Characters repeated: f, l, o
Note: Assume the length of the string is 10.
/*If you any query do comment in the comment section else like the solution*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main() {
char arr[1000];
int freq[26];
int i;
for(i=0;i<1000;i++)
arr[i]='\0';
for(i=0;i<26;i++)
freq[i]=0;
printf("Enter a string : ");
gets(arr);
printf("%s",arr);
for(i=0;i<strlen(arr);i++)
{
freq[toupper(arr[i])-65]++;
}
int count = 0;
for(i=0;i<26;i++)
{
if(freq[i] > 1) {
count++;
}
}
printf("Number of characters repeated: %d\n", count);
printf("Characters repeated: ");
for(i=0;i<26;i++)
{
if(freq[i] > 1) {
printf("%c",(97+i));
count--;
if(count != 0) {
printf(", ");
}
}
}
}
Get Answers For Free
Most questions answered within 1 hours.