Problem Description
How to find all occurrences of a character in a given string using for loop in C programming. Program to print all index of a character in a given string.CODING ARENA
#include<stdio.h>
#include<string.h>
int main()
{
char a,word[50];
int i=0;
scanf("%c",&a);
scanf("%s",word);
for(i=0;i<strlen(word);i++)
{
if(word[i]==a)
{
printf("%c is found at index %d\n",a,i);
}
}
return 0;
}
Test Case 1
Input (stdin)u srmuniversity
Expected Outputu is found at index 3
Test Case 2
Input (stdin)e srmuniversitylearningcentre
Expected Outpute is found at index 7 e is found at index 14 e is found at index 22 e is found at index 26
No comments:
Post a Comment