C++ Program to Search Alphabets in Given String Return with Position no.

  #include<iostream>

#include<iomanip>

#include<string.h>

using namespace std;

void line()

{

cout<<"========================================\n";

}

int main() 

{

int i,n,len=0,g=0;

char arr[20],ch,ch1=0;

line();

cout<<"String Programs #13\n";

line();

cout<<"Enter Any values to the String :";

cin.getline(arr,20);

line();

for(n=0;arr[n]!='\0';n++);

cout<<"Enter Whatever you want to search :";

cin>>ch;

for(i=0;i<n;i++)

    {

    if(arr[i]==ch)

    {

    g=i+1;

ch1=arr[i];

len++;

break;

}

    }

cout<<arr<<"  ";

    if(len==0)

    {

cout<<"Your number is absent in the string...";

}

else

cout<<"Your number is present at position "<<g;

}

Comments

Popular posts from this blog