Thursday, 9 January 2014

Count Repetition of Character in a string

Count Repetition of Character in a string


#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char ch[10],c;
int count=0;
clrscr();
printf("Enter any string= ");
gets(ch);
printf("Enter any character from string= ");
c=getch();
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]==c)
{
count++;
}
}
printf("\nrepitation of %c = %d times",c,count);
getch();
}

Output

Count Repetition of Character in a string

No comments:

Post a Comment