Question

Write a C program that counts the number of repeated characters in a phrase entered by...

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.

Homework Answers

Answer #1

/*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(", ");
            }
        }
        
    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that prompts the user to enter a string and displays the number of...
Write a program that prompts the user to enter a string and displays the number of characters it contains, fourth character, and last character. Note: The string may contain blanks. For example: “C++ programming is fun”. You should write a complete program.
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write an assembly program that reads characters from standard input until the “end of file” is...
Write an assembly program that reads characters from standard input until the “end of file” is reached. The input provided to the program contains A, C, T, and G characters. The file also may have new line characters (ASCII code 10 decimal), which should be skipped/ignored. The program then must print the count for each character. You can assume (in this whole assignment) that the input doe not contain any other kinds of characters.  the X86 assembly program that simply counts...
Write a Java program that counts the number of alphabetic ('A' to 'Z' in both upper...
Write a Java program that counts the number of alphabetic ('A' to 'Z' in both upper and lower case) and digit ('1' to '3') characters in a String. The method header is as follows: public static int countNumAlphabetic ( String str ) { } Sample Output: countNumAlphabetic("mA13Th9zB86") returns 8
Vowels and consonants Write a program that reads a word and prints the number of vowels...
Vowels and consonants Write a program that reads a word and prints the number of vowels and consonants in the word. For this exercise assume that ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, and ‘y’ are vowels. For example, if the user enters the input “Harry”, the program should print “The word contains 2 vowels and 3 consonants”.
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex:...
Color. Write a program that displays the color of the camera whose item number is entered...
Color. Write a program that displays the color of the camera whose item number is entered by the user. All item numbers contain exactly seven characters. All items are available in four colors: black, green, red, and white. The fourth character in the item number indicates the item’s color, as follows: a B or b indicates Black, a G or g indicates Green, an R or r indicates Red, and a W or w indicates White. If the item number...
C++: Write a function that receives a pointer to a character string consisting of only alphabets...
C++: Write a function that receives a pointer to a character string consisting of only alphabets a-z and returns the character with the maximum number of repetitions. If more than one-character repeats same number of times, return the character with smallest alphabetical order. For example, the string “Mississippi” has three repeated characters (i-4, s-4, p-2). Both ‘i’ and ‘s’ repeated 4 times but ‘i’ is alphabetically smaller hence the function should return ‘i’. Do not count repeated blanks, special characters,...
Write a C program. Many user-created passwords are simple and easy to guess. Write a program...
Write a C program. Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string. You may assume that the string does not contain spaces and will always contain less than 50 characters. i becomes ! a becomes @ m becomes M B becomes 8 o becomes . Ex: If the input...