SEARCH A CHARACTER IN ARRAY AND FIND ITS NUMBER OF TIMES

/*PROGRAM TO SEARCH A CHARACTER IN A CHARACTER ARRAY AND THEN FIND ITS NUMBER OF TIMES*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,count=0,j;
char ch,a[10],character;
clrscr();
printf(“Enter characters in the array:\n”);
i=0;
do
{
character=getchar();
a[i]=character;
i++;
}while(character!=’\n’);
i=i-1;
a[i]=’\n’;
printf(“Entered characters are:\n”);
for(j=0;j<i;j++)
{
printf(“%c\t”,a[j]);
}

printf(“\nEnter the character you want to search: “);
scanf(“%c”,&ch);
for(j=0;j<i;j++)
{
if(ch==a[j])
count++;
}
if(count==0)
printf(“%c is not found in the array”,ch);
else
printf(“%c is found %d times in the array”,ch,count);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *