Advertisement
7_2009-2012 Debugging and Error Handling #239636

Combination Program

This program takes a string and value of r as input and generates all the combinations which is equal to ncr

AI

KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Quellcode
original-source
#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);
        }
    }
}
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine