A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE
OUTPUT: E



A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / sreejesh1987

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
char str[20];
int max[20],x=1,high;

clrscr();

printf("Enter the string");
scanf("%s",str);//assas[s]iation
n=strlen(str);
for(i=0;i<n;i++)
max[i]=1;

for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
if(strcmp(str[i],str[j])==0)
{
max[i]++;

if(max[i]>x)
{
x=max[i];
high=i;
}

}

}
printf("%c is occured %d times",str[high],x);

getch();
}



Is This Answer Correct ?    21 Yes 1 No

Post New Answer

More C++ Code Interview Questions

what is virtual constroctor ? give an exam for it?-(parimal dhimmar)

2 Answers  


What will be the output- for(i=1;i<=3;i++) { printf("%d",i); continue; i++; }

5 Answers   Impetus,


Write a program to enter 10 number of integer entries into an array n and then odds up all the odd entries. the program then displays the result. plssss answer assss fast asss u can...

1 Answers  


how to take time as input in the format (12:02:13) from user so that controls remains between these columns?

0 Answers  


1+1/2!+1/3!+...+1/n!

0 Answers  






Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

0 Answers   Facebook, Webyog, Wipro,


Hello, I am trying to write a program in c++ which accepts month and year from the user and prints the calender. So please tell me the algorithm and what is the calender logic.

0 Answers  


Given 1 to n random number, find top 10 maximum numbers and explain the time complexity of the algorithm.

1 Answers   IMO, NetApp,


#include<iostream.h> //main() //{ class A { friend class B; public: void read(); }; class B { public : int a,b; }; void A::read() { cout<<"welcome"; } main() { A x; B y; y.read(); } In the above program......, as B is a friend of A B can have access to all members,i cant access y.read . could you please tell me the reason and what would i code to execute this program?

2 Answers  


write a program to perform generic sort in arrays?

0 Answers  


. Write a program using two-dimensional arrays that computes the sum of data in tows and the sum of data in columns of the 3x3 (three by three) array variable n[3][3].

2 Answers   IBM,


write a program that accepts a number and outputs its equivalent in words. take note that the maximum input is 3000

1 Answers   Alvin,


Categories