Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


program to find which character is occured more times in a
string and how many times it has occured? for example in
the sentence "i love india" the output should be i & 3.

Answers were Sorted based on User's Feedback



program to find which character is occured more times in a string and how many times it has occure..

Answer / venkatesh sabinkar

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ch[30],t,i1;
int i,j,max=1,n=1;
clrscr();
printf("enter the sentence\n");
gets(ch);
for(i=0;i<strlen(ch);i++)
{
for(j=i+1;j<strlen(ch);j++)
{
if(ch[i]>ch[j])
{
t=ch[i];
ch[i]=ch[j];
ch[j]=t;
}
}
}
printf("\n%s",ch);
for(i=0;i<strlen(ch);i++)
{
if(ch[i]==ch[i+1])
{
n+=1;
}
if( max<n)
{
max=n;
i1=ch[i];
}

}
printf("\n%c %d",i1,max);
getch();
}

Is This Answer Correct ?    7 Yes 3 No

program to find which character is occured more times in a string and how many times it has occure..

Answer / vignesh1988i

add k++; in line 32.... sorry for mistake.



thank you

Is This Answer Correct ?    0 Yes 0 No

program to find which character is occured more times in a string and how many times it has occure..

Answer / vignesh1988i

#include<stdio.h>
#include<conio. h>
void main()
{
char str[100],*ptr[50],a;
int count=0,count2=0,count,k=0;
printf("enter the string :");
fflush(stdin);
gets(str);
for(int i=0;str[i]!='\0';)
{
count=0;

if(str[i]==' ')
{
i++;
contine;
}
for(int j=i;str[j]!='\0';j++)
{
if(str[j]==' ')
continue;
if(str[i]==str[j])
count++;
}
if(count>count1)
{
count1=count;
a=str[i];
}
ptr[k]=&str[i];
i++;
count2++;
for(j=0;j<count2;j++)
{
if(str[i]==*(*(ptr+j)))
{
i++;
j=-1;
}
}
}
printf("the occurance of the char. is %c , count is %d times",a,count1);
getch();
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

Write a c program to demonstrate Type casting in c?

2 Answers  


Who is the founder of c language?

0 Answers  


Is c pass by value or reference?

0 Answers  


Is c an object oriented programming language?

1 Answers  


what type of questions arrive in interview over c programming?

0 Answers  


write a program in c language to print your bio-data on the screen by using functions.

0 Answers  


why integer range between -327680to+32767

2 Answers  


Find Index of least significant bit set in an Integer. ex. int value is say 10001000 results should be 4.

1 Answers  


What is pivot in c?

0 Answers  


What is a good data structure to use for storing lines of text?

0 Answers  


What is scanf () in c?

0 Answers  


Explain what is a stream?

0 Answers  


Categories