for eg: user entered =5 
1+1+1+1+1 
1+4 
2+3 
3+1+1 
1+2+2 
1+1+1+2  #include<stdio.h>
#include<conio.h>
void ste(int);

int main()
{
	int cnt,n1,i,temp,n2,n3,n4,n5,z;

	z=cnt=0;

	clrscr();

	printf("enter any number");
	scanf("%d",&n1);

	for(i=n1;i>1;i--)
	{
		for(n2=i-1;n2>=i/2;n2--)
		{
			for(n3=i/2;n3>0;n3--)
			{
				temp=n2+n3;

				if(temp==i)
				{
					if(!(n2==n5&&n3==n4))

					{
						printf("%d+%d",n2,n3);
						ste(z);
						cnt++;
						n4=n2;
						n5=n3;
					}//if
				}//if

			}//for

		}//for
		z++;
		printf("\n");
	}//for
	printf("Number of partion is %d",cnt);
	getch();
	return(0);
}//main

void ste(int x)
{
	char ch[8]="+1",ch2[400]="\0";
	int i;
	for(i=0;i<x;i++)
	{
		strcat(ch2,ch);
	}//for
	printf("%s,  ",ch2);

}//int
Partition of a number

Leave a Reply

Your email address will not be published.