ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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.
 Question Submitted By :: Nag
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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.
Answer
# 1
#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 ?    4 Yes 0 No
Venkatesh Sabinkar
 
  Re: 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.
Answer
# 2
#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
Vignesh1988i
 
 
 
  Re: 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.
Answer
# 3
add k++; in line 32.... sorry for mistake.



thank you
 
Is This Answer Correct ?    0 Yes 0 No
Vignesh1988i
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??  4
What is the difference between char a[] = "string"; and char *p = "string"; ? Honeywell11
Write an implementation of “float stringToFloat(char *str).” The code should be simple, and not require more than the basic operators (if, for, math operators, etc.). • Assumptions • Don’t worry about overflow or underflow • Stop at the 1st invalid character and return the number you have converted till then, if the 1st character is invalid return 0 • Don’t worry about exponential (e.g. 1e10), instead you should treat ‘e’ as an invalid character • Write it like real code, e.g. do error checking • Go though the string only once • Examples • “1.23” should return 1.23 • “1a” should return 1 • “a”should return 0 Qualcomm5
what is the difference between declaration ,defenetion and initialization of a variable? LG-Soft5
what is the differnce between AF_INET and PF_INET? Wipro2
what is self refrential structure HCL2
write a C program to print the program itself ?! TCS12
C,c++, Java is all are structural oriented or procedure oriented language..?  3
what is use#in c  3
without using arithmatic operator convert an intger variable x into x+1  1
which of the following statements is incorrect a.typedef struct new{ int n1; char n2; } DATA; b.typedef struct { int n3; char *n4; }ICE; c.typedef union { int n5; float n6; } UDT; d.#typedef union { int n7; float n8; } TUDAT; TCS5
Dear Sir, we are required the bubble sorting programs Regs Prem  1
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice) Subex1
difference between function & structure Verizon5
Which of the Following is not defined in string.h? A)strspn() B)strerror() C)memchr() D)strod() Accenture1
Write a program in c to input a 5 digit number and print it in words.  1
How to add two numbers with using function?  3
will the program compile? int i; scanf(“%d”,i); printf(“%d”,i);  2
what is meant by c  4
#define DCHAR char* typedef char* TCHAR; if using these following variables will be declared like DCHAR ch1, ch2; TCHAR ch3, ch4; then what will be types of ch1, ch2, ch3 and ch4? NDS1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com