473,466 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

can we do looping inside recursion function

3 New Member
hai
i wrote a program for sudoku puzzle .... for that i need to go for recursion function . inside the function i have go for looping.... where i have call the rec..function again..

but it not works... is it possible ...if so how....
Apr 4 '07 #1
4 1928
sicarie
4,677 Recognized Expert Moderator Specialist
hai
i wrote a program for sudoku puzzle .... for that i need to go for recursion function . inside the function i have go for looping.... where i have call the rec..function again..

but it not works... is it possible ...if so how....
I'm sure you could, here are a couple links on recursion, more than that, it really depends on your implementation.
Apr 4 '07 #2
Ganon11
3,652 Recognized Expert Specialist
You can implement recursion in many ways. I had to write a recursive function that called itself within a loop. It was horribly inefficient, but necessary to solve the problem.
Apr 4 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
Ganon11, did you have a book that you got that from, or are there a few good online links? (Mine's just a google search...)
Apr 4 '07 #4
Ganon11
3,652 Recognized Expert Specialist
It was actually from a programming competition. Here is the PDF file of all the questions, the one I'm talking about is Question #8. You are also provided with the following code to start with:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. /**
  5.  * Compute ways of making change
  6.  *
  7.  * This program computes the number of ways of making change from a
  8.  * given currency system.  
  9.  * 
  10.  * For the UMD High School Programming Contest, 2006.
  11.  * @author Dave Mount
  12.  */
  13. public class Change {
  14.  
  15.     public static void main(String[] args) throws Exception {
  16.  
  17.         /* read input */
  18.         Scanner scanner = new Scanner( System.in );
  19.  
  20.         int nCoins = scanner.nextInt();
  21.         int[] coins = new int[nCoins];
  22.         for (int i = 0; i < nCoins; i++) {
  23.             coins[i] = scanner.nextInt();
  24.         }
  25.         int total = scanner.nextInt();
  26.  
  27.         /* echo input */
  28.         System.out.print("Coins:");
  29.         for (int i = 0; i < nCoins; i++) {
  30.             System.out.print(" " + coins[i]);
  31.         }
  32.         System.out.println("\nTotal: " + total);
  33.  
  34.         /* compute and print result */
  35.         int result = countCombinations(coins, total);
  36.         System.out.println("Number of combinations: " + result);
  37.     }
  38.  
  39.     /** Counts the number of possible coin combinations for given total.
  40.      *  
  41.      *  @param    coins Array containing the coin value (ascending order).
  42.      *  @param    total Total amount of change to make.
  43.      *  @return    The number of combinations.
  44.      */
  45.     private static int countCombinations(int[] coins, int total) {
  46.                 int result = 0;
  47.         /* ------------------- INSERT CODE HERE ---------------------*/
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.         /* -------------------- END OF INSERTION --------------------*/
  70.                 return result;
  71.  
  72.     }
  73. }
Apr 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: JP SIngh | last post by:
Hi All Please can someone help me solve this issue. I have a database table the structure of which are given below. Profile Table EmployeeNumber FirstName
27
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this...
43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
11
by: Dacuna | last post by:
Is it possible to use a recursive function to loop through a recordset faster? I have a table that I need to edit its contents after doing some calculation. The table has one field has an RawData...
7
by: astro | last post by:
I am not farmilar with the object model for webforms. I want to loop through the web form controls - pulling out the checkboxes on the form like the following: For Each ctrl In Me.Controls ...
19
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
13
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What...
1
by: dennis.sprengers | last post by:
Consider the following array and string: $trail = array('products/veggies', 'products', 'services/cleaning'); $path = 'products/veggies/1243/more'; I am trying to write a function that matches...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.