Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next

 
Palindrome
Reply
Posted 2004-11-09, 01:41 PM
Can someone help me edit my program I do not know how to change to code from C++ to C.

#include <iostream.h>
#include <conio.h>
#include <string.h>
using namespace std;

//---------------------------------------------------------------------------

bool Palindrome(int first, int last, char inputString[]);

int main()
{
int first = 0;// first index for array
int last = 0;// last index for array
char inputString[100];//initialize size of array


cout << "This program determines whether the word"
<< endl
<< "or sentence entered by user is a palindrome."
<< endl;

cout << "\n\nPlease enter a word or phrase: ";

cin >> inputString;//receive input from user
last = strlen(inputString);//store input into character array

if (Palindrome(first,last - 1,inputString)== true)
cout << "Input is classified as a palindrome.";
else
cout << "Input is not classifed as a palindrome.";

getch();

return 0;
}

bool Palindrome(int first, int last, char *inputString)
{

//if the next first index is greater than the next last index
//program concludes that all the elements in array have been compared
//and therefore input should be a palindrome retuned as true.
if (first > last)
return true;

//if next first element and next last element are not the same
//therefore word is not a palindrome returned as false
if (inputString[first]!= inputString[last])
return false;

//if next first element and next last element are same
//call Palindrome function again, increment first element by one
//decrement last element by one to compare if those two elements
//in array are equal.Continue this process until next first element
//and next element are not equal.
else if (inputString[first] == inputString[last])
{
return Palindrome((first+1),(last-1),inputString);
}
}
Old
Profile PM WWW Search
deadlock75 is neither ape nor machine; has so far settled for the in-betweendeadlock75 is neither ape nor machine; has so far settled for the in-between
 
deadlock75
 



 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 05:24 PM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.