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



LinkBack URL
About LinkBacks


