Generate all possible combinations of 1, 2, 3 using for loop.
Write a program to generate all combinations of 1, 2 and 3 using for loop.
#include<stdio.h>
main()
{
int i, j, k;
for (i=1; i<=3; i++)
{
for (j=1; j<=3; j++)
{
for (k=1; k<=3; k++)
printf("\n%d %d %d", i, j, k);
}
}
}
The file can be found at:
Download File
#include<stdio.h>
main()
{
int i, j, k;
for (i=1; i<=3; i++)
{
for (j=1; j<=3; j++)
{
for (k=1; k<=3; k++)
printf("\n%d %d %d", i, j, k);
}
}
}
The file can be found at:
Download File
Comments
what could be the problem ???
do continue posting c programs.
thanks a lot , pal !!!
well..I don't see what display function are you talking about..
Its a basic rule of functions though...you need to define a function (prototype) before you can actually use it..
Check out the other programs to get an idea about functions..
Well..all of my programs are checked..they run properly without any glitches..
Sometimes to hold the output on the screen, you may have to add a getch(); statement to your program, but clearly I don't put it there.
http://rapidshare.com/files/89852054/123COMBI.C.html
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!
you can use the "if" to print the unrepeated combinations only as given below:
int main ()
{
int i j k;
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
{
for(k=1;k<4;k++)
{
if((i!=j) && (j!=k) && (i!=k))
{
printf(" d d dn" i j k);
}
}
}
}
}
and then print their combination?
#include
#include
int nCk(int n,int loopno,int ini,int *a,int k)
{
static int count=0;
int i;
loopno–;
if(loopno<0)
{
a[k-1]=ini;
for(i=0;i<k;i++)
{
printf("%d,",a[i]);
}
printf("\n");
count++;
return 0;
}
for(i=ini;i<=n-loopno-1;i++)
{
a[k-1-loopno]=i+1;
nCk(n,loopno,i+1,a,k);
}
if(ini==0)
return count;
else
return 0;
}
void main()
{
int n,k,*a,count;
printf("Enter the value of n and k\n");
scanf("%d %d",&n,&k);
a=(int*)malloc(k*sizeof(int));
count=nCk(n,k,0,a,k);
printf("No of combinations=%d\n",count);
}
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=i-1;j>=1;j++)
{
printf("%d",j);
printf("\n")
}
}
return (0);
}
int digits[6]
for i
digit[i] = 1
for j
digit[j] = 1
for k
digit[k] = 1
...
if igit[1]+digit[2]+digit[3]=3
This checks every combination then finds the good ones. I suppose you could speed it up by checking at each level (if the first two are different, try a third)
and 3
Add this header file
The combination of 1,2 and 3 should be.......
#include
int main (void)
{
int i,j,k;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
{
if(i!=j&&j!=k&&k!=i)
printf("%d%d%d ",i,j,k);
}
}
}
return 0;
}