Question

In: Computer Science

This is for C programming. Suppose one string is defined for a sentence with maximum 100...

This is for C programming.

Suppose one string is defined for a sentence with maximum 100 characters.

Write a method that prints maximum occurring characters in the input string and its frequency. For example, if input string is "this is testt", your code should print 't' : 4.

Thank you.

Solutions

Expert Solution

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include<stdio.h>

void printMax(char s[],int n)
{
int i,arr[26];
for(i=0;i<26;i++)
arr[i]=0;
for(i=0;i<n;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
arr[s[i]-'a']++;
}
else if(s[i]>='A'&&s[i]<='Z')
{
arr[s[i]-'A']++;
}

}
int ind=0,max=arr[0];
for(i=0;i<26;i++)
{ if(max<arr[i])
{
max=arr[i];
ind=i;
}
}

printf("'%c' : %d\n",(ind+'a'),arr[ind]);
}
int main(){
char s[100];
printf("Enter string: ");
gets(s);
printMax(s,strlen(s));
return 0;
}

Kindly revert for any queries

Thanks.


Related Solutions

in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
C programming Write a function called string in() that takes two string pointers as arguments. If...
C programming Write a function called string in() that takes two string pointers as arguments. If the second string is contained in the first string, have the function return the address at which the contained string begins. For instance, string in(“hats”, “at”) would return the address of the a in hats. Otherwise, have the function return the null pointer. Test the function in a complete program that uses a loop to provide input values for feeding to the function.
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
Python please A string is one of most powerful data types in programming. A string object...
Python please A string is one of most powerful data types in programming. A string object is a sequence of characters and because it is a sequence, it is indexable, using index numbers starting with 0. Similar to a list object, a string object allows for the use of negative index with -1 representing the index of the last character in the sequence. Accessing a string object with an invalid index will result in IndexError exception. In Python a string...
What are the diagrams defined in the UML Standard. Give a one or two sentence description...
What are the diagrams defined in the UML Standard. Give a one or two sentence description of each one.
IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX...
IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX INPUT: B C D A OUTPUT: D C B A #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]) {         int MAX = 100000;         int i =0;         int k =0;         int j =0;         char array[MAX];         char split[] = " ,.-!?()0123456789";         int n = 0;         char second[MAX];         printf("Please enter in a String: ");...
C++: A string construction problem defined as follows: - You are given as input a target...
C++: A string construction problem defined as follows: - You are given as input a target string - Starting with an empty string, you add characters to it, until your new string is same as the target. You have two options to add characters to a string: - You can append an arbitrary character to your new string, with cost x - You can clone any substring of your new string so far, and append it to the end of...
1.In C++, C#, Java. Discuss string operations functions, with examples. Then make Comparison of programming languages  ...
1.In C++, C#, Java. Discuss string operations functions, with examples. Then make Comparison of programming languages   2.String and StringBuffer (C#, Java) with examples.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT