C Program to Take input any number (N>=10) from user and also take one number(s).N number is divided into 5 numbers or parts where all 5 parts where all 5 parts are prime number and total of that number of parts total is equivalent to N.
C program
Sample Example :
N=17
S=7
1+1+1+1+1+1+11=17
1+1+1+1+1+5+7=17
1+1+1+1+3+5+5=17
1+1+1+3+3+3+5=17
1+1+2+2+3+3+5=17
1+2+2+3+3+3+3=17
Code:
#define arrsize 100
#include<stdio.h>
int n,s,max;
void print(int arr[], int arr_size);
int prime(int);
void combination(int, int);
void main()
{
clrscr();
printf("\nEnter the number :");
scanf("%d",&n);
if(n<0)
{
printf("Number Must be Greater than 10 : %d\n", n);
getch();
exit(0);
}
max=n;
printf("How Many ways :");
scanf("%d",&s);
combination(n, 0);
getch();
}
void combination(int n, int i)
{
static int arr[arrsize];
if(n==0)
{
print(arr, i);
}
else if(n>0)
{
int k,temp;
for(k=1;k<=max;k++)
{
temp=0;
temp=prime(k);
if(temp==1)
{
arr[i]= k;
combination(n-k,i+1);
}
}
}
}
void print(int arr[], int arr_size)
{
int i;
if(arr_size==s)
{
for(i=0;i<arr_size;i++)
{
printf("%2d ",arr[i]);
}
printf("= %d\n",n);
getch();
}
}
int prime(int n)
{
int i,flag=1;
for(i=2; i<=n/2; ++i)
{
if(n%i==0)
{
flag=0;
break;
}
}
return flag;
}
Complex Range Prime Number
Reviewed by Unknown
on
6:40 pm
Rating:
No comments: