Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   Palindrome (http://zelaron.com/forum/showthread.php?t=34458)

deadlock75 2004-11-09 01:41 PM

Palindrome
 
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);
}
}

WetWired 2004-11-10 06:39 AM

Lookup printf and scanf to replace cin and cout, and you should be fine.


All times are GMT -6. The time now is 06:14 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.