C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 4th, 2012, 07:17 AM
whitedragon whitedragon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 whitedragon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 57 sec
Reputation Power: 0
Help on recursion

Hey all, I can't seem to figure out my recursion assignment. I'm able to compile but the program does not return the right answer. Could someone please enlighten me on it? Thank you.

18 int main(void) {
19 int temp, i, start, end, size =0, count =0, num[MAX_SIZE] = {0};
20
21 printf("Enter start and end: ");
22 scanf("%d %d", &start, &end);
23
24 while(start <= end) {
25 temp = start;
26 for(i=0;temp>0;i++) {
27 num[i] = temp % 10;
28 temp /= 10;
29 size++;
30 }
31 count += isPalindrome(num, size);
32 start++;
33 }
34
35 printf("Number of palindrome numbers = %d\n", count);
36
37 return 0;
38 }
39
40 // Return 1 if arr is a palindrome, or 0 otherwise.
41 // Driver function to call recursive function palindromeRecur()
42 int isPalindrome(int arr[], int size) {
43 int i=0;
44 return palindromeRecur(arr, i, size);
45 }
46
47 // Return 1 if arr is a palindrome, or 0 otherwise.
48 // Recursive function
49 int palindromeRecur(int arr[], int i, int size) {
50 if(size <= i)
51 return 1;
52
53 if(arr[i] != arr[size])
54 return 0;
55 else return palindromeRecur(arr, i+1, size-1);
56 }

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help on recursion


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap