| | |
my first recursion program... :/
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2005
Posts: 46
Reputation:
Solved Threads: 0
This is my first recursion project and i have no idea if i'm even going about it the right way...It's a palindrome checker, which checks for integers. I can't check it character by character as a string. It compiles clean but when i execute it i get weird results like "4280412". It is supposed to display "yes" or "no" here is my code: could someone please help me figure out or tell me what i'm doing wrong?
C Syntax (Toggle Plain Text)
void CLab13Dlg::OnClear() //button that clears both edit boxes { SetDlgItemText(IDC_NUMBER, ""); SetDlgItemText(IDC_PALINDROME, ""); } void CLab13Dlg::OnCheck() //button to check if integer is a palindrome { GetDlgItemText(IDC_NUMBER, m_number); int length = m_number.GetLength(); //length of the string int number = atoi(m_number); palindrome(number, length); if(palindrome(number,length)==true) { m_palindrome.Format("%d", "Yes"); SetDlgItemText(IDC_PALINDROME, m_palindrome); } else if(palindrome(number, length) == false) { m_palindrome.Format("%d", "No"); SetDlgItemText(IDC_PALINDROME, m_palindrome); } } bool CLab13Dlg::palindrome(int number, int length) { int value = (int)pow(10, length-1); if(length == 1) { return(true); } else if(number/value == number%10) { number = number%value; number = number / 10; length= length - 2; palindrome(number, length); return(true); } else { return(false); } }
![]() |
Similar Threads
- Tracing through a recursion program. (Java)
- Recursivity (C++)
- modulus operator % (C)
- Thanks...Problem Solved--Re: Recursion Program/Code I'm having issues with... (Java)
- Recursion Program/Code I'm having issues with... (Java)
Other Threads in the C Forum
- Previous Thread: compiling error, tried debugging but no luck
- Next Thread: Can Someone please check my project & comment/tips
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h





