The Code given below can be used in TURBO C++ Compilers: -
#include<iostream.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char str[50];
char letter;
cout << "Enter a Word: ";
cin >> str;
cout << "Enter the letter to find the position of it: ";
cin >> letter;
char *chr = strchr(str, letter);
cout << "The position of " << letter << " is " << chr - str + 1;
getch();
}
//........Coded by YASH ALAPURIA
The Code given below can be used in gcc/g++ Compilers: -
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
system("cls");
char str[50];
char letter;
cout << "Enter a Word: ";
cin >> str;
cout << "Enter the letter to find the position of it: ";
cin >> letter;
char *chr = strchr(str, letter);
cout << "The position of " << letter << " is " << chr - str + 1;
return 0;
}
//........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP