View Single Post
  #1 (permalink)  
Old October 28th, 2004, 03:11 PM
amahja56 amahja56 is offline
Authorized User
 
Join Date: Jan 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default i need explanation ...

i have c++ book...and there is a question about checking if the strng is palindrome or not.....before i look into the solution at the last page of the book...i have tried alot to do it myself..but unfrtunately i couldnt do it........so..i pened the solution page and here is the solution of the book :

# include <iostream.h>
# include <conio.h>

int main()

{
    char text[80];
    int beg;;
    int back;
    int flag;
    int l;

    cout<<"Enter the string:"<<endl;
    cin>>text;

    l=0;


    while(text[l] != '\0')
        l++;
        flag=1;
        beg=0;
        back=l-1;

    while( (beg<=back) && flag )
    {
        if(text[beg] == text[back])
            flag=1;
        else
            flag=0;
        beg++;
        back--;
    }

    if(flag)

    cout<<"Yes its a palindrome"<<endl;
    else
        cout<<"No its not a palindrome"<<endl;
}


what i dont understand is the logic of this program really..!

int beg ...> is the beginig of the text
int back...> the end of the text....

why they are declared as integers?

int flag....> what is flag?
i didnt understand this word


thank you very much

Reply With Quote