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
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 |
Answer / vignesh1988i
add k++; in line 32.... sorry for mistake.
thank you
| Is This Answer Correct ? | 0 Yes | 0 No |
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 |
a number whose only prime factors are 2,3,5, and 7 is call humble number,,write a program to find and display the nth element in this sequence.. sample input : 2,3,4,11,12,13, and 100.. sample output : the 2nd humble number is 2,the 3rd humble number is 3,the 4th humble number is ,the 11th humble number is 12, the 12th humble number is 14, the 13th humble number is 15, the 100th humble number is 450.
#include <stdio.h> int main() { int i; for (i=0;i<3;++i) { fork();fork(); } } How many processes are created when running this program (including the initial one)? Explain ؟؟؟
program to find the magic square
Is calloc better than malloc?
What is define c?
What is the use of void pointer and null pointer in c language?
How variables are declared in c?
What is the significance of c program algorithms?
program in c to print 1 to 100 without using loop
Is it possible to use curly brackets ({}) to enclose single line code in c program?
Write a program to interchange two variables without using the third variable?
17 Answers Accenture, College School Exams Tests, Infotech,
#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }