VB icon

Combination Program

Email
Submitted on: 1/10/2015 4:10:00 AM
By: Akash Khaitan (from psc cd)  
Level: Advanced
User Rating: By 2 Users
Compatibility: C
Views: 1702
 
     This program takes a string and value of r as input and generates all the combinations which is equal to ncr

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Combination Program
// Description:This program takes a string and value of r as input and generates all the combinations which is equal to ncr
// By: Akash Khaitan (from psc cd)
//**************************************

#include<stdio.h>
#include<string.h>
int r=0,q=0;
char as[50],bs[50];
int main(void)
{
void combination(int,int,int);
int nk=0;
printf("Enter a String : ");
gets(as);
printf("Enter the value of r : ");
scanf("%d",&r);
nk=strlen(as)-r;
combination(0,nk,0);
printf("No of Combinations : %d\n",q);
return 0;
}
void combination(int i,int nk,int x)
{
for(i;i<=nk;i++)
{
bs[x]=as[i];
if(nk==strlen(as)-1)
{
bs[x]=as[i];
puts(bs);
q++;
}
if(nk<strlen(as)-1)
{
combination(i+1,nk+1,x+1);
}
}
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.