DIGIT-ARC read-only archive · snapshot: July 23, 2026

C Programming ... Help Needed...

6 posts · originally from https://geek.digit.in/community/threads/c-programming-help-needed.15724/

V
vinayasurya Original post #1
Sep 19, 2005 at 4:45 PM
Can u suggest me any way to print all the combinations of a string using C language. This is an assignment and I found no way to do that.. Plz help..
QwertyManiac
Sep 19, 2005 at 5:08 PM
can u plz elaobrate wat is combo of strings plz ?

me dont gets u, srry.
A
Sep 19, 2005 at 8:01 PM
combo of a string
do u mean
abc ==> abc, bac, cab ?
A
Sep 19, 2005 at 8:11 PM
chech this out.. u'll get some info...
*mathforum.org/library/drmath/view/56109.html
NikhilVerma
Sep 19, 2005 at 9:23 PM
Enjoy ! :D

Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void swap(int &a,int &b)
{
	int c=a;
	a=b;
	b=c;
}
void comb(char str[],int &l,int arr[],int ch,int &p,int &n)
{
	if(p<1)
		p=n-1;
	if(ch!=0)
	{
		swap(arr[p],arr[p-1]);
		for(int i=0;i<n;i++)
			cout<<str[arr[i]];
		cout<<endl;
		comb(str,l,arr,ch-1,p-1,n);
	}
}
void main()
{
	clrscr();
	char str[20];
	int n,l,arr[20];
	cout<<"Input a word (less than 10 letters)"<<endl;
	gets(str);
	cout<<"Enter no of letters"<<endl;
	cin>>n;
	for(int i=0;i<n;i++)
		arr[i]=i;
	l=strlen(str);
	comb(str,l,arr,n*(n-1),n-1,n);
	getch();
}


Made using recursion...
Please do credit the author that is me !
:wink:
V
Sep 25, 2005 at 12:08 AM
Thanks a lot.......