Thread: Integer partition

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Exclamation Integer partition

    can someone give me the c code for integer partitoning

    i.e. for the integer 4 u must print

    4
    3 1
    2 2
    2 1 1
    1 1 1 1

    The java code for this is as follows, I want much simpler version of the following code.

    Code:
    import java.util.Scanner;
    
    public class Partition {
    
        
        public static void partition(int n, int max, String prefix) {
            if (n == 0) {
                System.out.println(prefix);
                return;
            }
    
            for (int i = Math.min(max, n); i >= 1; i--) {
                System.out.println ("partition(" 
                                    + (n-i)
                                    + "," 
                                    + i
                                    + "," 
                                    + "prefix + i="
                                    +i
                                    + ")"
                                    );
                partition(n-i, i, prefix + " " + i);
            }
        }
    
    
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            System.out.print("Enter a no");
            int N = sc.nextInt();
            partition(N,N, "");
        }
    
    }

    Thankz in advance

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    So you want us to just do your homework for you?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    bithub, ive wrote the c code in the following thread:
    Integer partitioning

    but it isn't working

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Spamming won't help your cause - closed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM

Tags for this Thread