Programming in "C‟ | Write a „C‟ program to enter a string and a character. Count number of times that character appears in entered string and display the count

#include<stdio.h>

#include<conio.h>

void main()

{

char str[10],ch;

int i=0,count=0;

clrscr();

printf("Enter string:");

gets(str);

printf("Enter character:");

scanf("%c",&ch);

while(str[i]!='\0')

{

if(str[i]==ch)

{

count++;

}
i++;
}
printf("\n Count=%d",count);
getch();
 (Note: Any other correct logic shall be considered).

Post a Comment

0 Comments