Program that displays the position of a character in the string if character match
Source Code:
#include<stdio.h>
void main()
{
char x[30];
char c;
int i;
printf("enter the string:\n");
scanf("%s",x);
printf("enter the char to which its position is to be found:\n");
scanf("%c",&c);
for(i=0;x[i]!=NULL;i++)
{
if(x[i]==c)
{
printf("the position of %c is:%d\n",c,i);
}
}
}
Output:
enter the string:
hello
enter the char to which its position is to be found:
enter the char to which its position is to be found:
l
the position of l is:
the position of l is:
2
the position of l is:
3
No comments:
Post a Comment