GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 372 of 453    Print  
how to print all the combinations of a given integer
suppose i have given like integer 123.....then print like all the combinations 111,112,113,121......up to 333..


  
Total Answers and Comments: 3 Last Update: February 17, 2009     Asked by: bajjuri.thirupathi 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
December 14, 2007 01:34:59   #1  
Sandeep Peddi Member Since: December 2007   Contribution: 1    

RE: how to print all the combinations of a given integer

This program works fine only for a number containing three digits.

But i prefer to intake these three digits at the time of scanning as a string rather than a single number for the flexibility of the program.


#include<string.h>
#include<stdio.h>


main()
{
char string_of_integers[4];
char first 0;
char second 0;
char third 0;


printf("nGive any three digit number");
scanf("n s" string_of_integers);


printf("nThe required combinations are:n")


for(first 0;first< 2;first++)
for(second 0;second< 2;second++)
for(third 0;third< 2;third++)
printf(" c c ct" string_of_integers[first] string_of_integers[second] string_of_integers[third]);


printf("nThis is the end of the program");
getch();

}

Expand the logic to make it work for more number of digits and also use some additional verificational logic if you are to work with varying number of digits i mean you need to add extra logic if at all flexibility needs to be a attribute of the program.


 
Is this answer useful? Yes | No
December 24, 2007 10:09:45   #2  
ravi_529 Member Since: December 2007   Contribution: 6    

RE: how to print all the combinations of a given integer
int main(int argc char* argv[])
{
int i j k;
int n r;
int dig[3];

printf("enter any three dig numbern");
scanf(" d" &n);

dig[2] n 10;
n n/10;
dig[1] n 10;
n n/10;
dig[0] n 10;

for(i 0;i<3;i++)
for(j 0;j<3;j++)
for(k 0;k<3;k++)
printf(" d d dn" dig[i] dig[j] dig[k]);

return 0;
}

 
Is this answer useful? Yes | No
February 17, 2009 09:59:37   #3  
bathesabari Member Since: February 2009   Contribution: 1    

RE: how to print all the combinations of a given integer

/*to print possible patern using given no*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100] b[100] n x 1 y k j i m c;
clrscr();
printf("enter no of nost");
scanf(" d" &n);
m n-1;
printf("nenter nost");
for(i 0 c m;i<n;i++ c--)
{
printf("n");
scanf(" d" &a[i]);
b[c] a[i];
}
for(i 1;i< n;i++)
{ x x*i; }
printf(" dnnn" x);

y x/2;
for(i 0;i<x;i++)
{
if(i<y)
{
for(j 0;j<n;j++)
{
if(j 0)
a[n] a[0];
k j+1;
a[j] a[k];
printf(" d " a[j]);
}


}
else
{

for(j 0;j<n;j++)
{
if(j 0)
b[n] b[0];
k j+1;
b[j] b[k];
printf(" d " b[j]);
}
}
printf("nn");
}
getch();
}


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape