Results 1 to 7 of 7

Thread: C Program to print Combination of numbers

  1. #1
    Join Date
    Dec 2009
    Posts
    48

    C Program to print Combination of numbers

    Hi friend,

    From few days I have been trying to code the C program to print the combination of given numbers without any success. For example suppose we provide 1, 2, and 3 numbers as a input to the program. When we run this program then it should print the all possible combination of the numbers 1, 2 and 3. If you posses the example for this number combination then please provide me that. I am waiting for your reply.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: C Program to print Combination of numbers

    Try something below to print the Combination of numbers:
    #include<stdio.h>
    Void main ()

    {
    int a1,b1,c1;

    for(a1=1;a1<4;a1++){

    for(b1=1;b1<4;b1++){

    for(c1=1;c1<4;c1++){
    if((a1! b1) && (b1! c1) && (a1! c1)){

    printf(" %d%d%d \n" a1,b1,c1);

    }
    }
    }
    }
    }

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: C Program to print Combination of numbers

    Hello friend,

    I suggest you to use the following code of 'For Loop' in your program for printing the number Combination. Which will determine all the combination of inputted numbers.
    for(num1=1;num1<4;num1++)
    {
    for(num2=1;num2<4;num2++)
    for(num3=1;num3<4;num3++)
    printf(" %d %d %d" num1, num1, num3);
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: C Program to print Combination of numbers

    Hi, Have you tried following C program code to print Combination of numbers?
    #include<stdio.h>
    #include<conio.h>

    void main()
    {
    int iz,jz,kz,lz,mz;
    clrscr();
    for(iz=0;iz<4;iz++)
    {
    for(jz=iz+1;jz<=4;jz++)
    {
    printf("%d",jz);
    }
    for(kz=1;kz<=iz;kz++)
    {
    printf("%d",kz);
    }
    printf("\n");
    for(kz=iz;kz>=1;kz--)
    {
    printf("%d",kz);
    }
    for(jz=4;jz>=iz+1;jz--)
    {
    printf("%d",jz);
    }
    getch();
    }

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: C Program to print Combination of numbers

    I have used below program code to print number combination. This code is running successfully without any error. You should try this code.
    #include <stdio.h>

    int main(int argce, char** argve)
    {
    int ae,be,ce,de;

    for(ae=1; ae<5; ae++){
    for(be=1; be<5; be++){
    for(ce=1; ce<5; ce++){
    for(de=1; de<5; de++){
    if(!(ae==be || ae==ce || ae==de || be==ce || be==de || ce==de))
    printf("%d%d%d%d\n",ae,be,ce,de);
    }
    }
    }
    }

    return 0;
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: C Program to print Combination of numbers

    C Program to print Combination of numbers:
    Void main()
    {int at,bt,ct,dt,nt = 4;
    int kt[10]={1,2,3,4,5};

    int main()
    {
    for (at = 0; at <= nt - 3; ++at)
    {
    for (bt = at+1; bt <= nt-2; bt++)
    {
    for (ct = bt+1; ct<= nt-1; ct++)
    {
    for (dt = ct+1; dt <= n; dt++)
    {
    printf("%d,%d,%d,%d", kt[at],kt[bt],kt[ct],kt[dt];
    }
    }
    }
    }
    }
    }

  7. #7
    Join Date
    Mar 2010
    Posts
    1

    Re: C Program to print Combination of numbers

    Hi dudes . . .
    ur answer to the combination question was really great but i steel need mor help . in looking 4 a code in c witch gets two numbers as input and shows all possible combinations of them . and the output should be sorted . u will make me very happy if u help !!!!
    All the best ...
    the king solo
    p.s. can u send me a copy of answer to my email please? this is my email : armanjudo@yahoo.com

Similar Threads

  1. Replies: 6
    Last Post: 31-12-2011, 05:42 PM
  2. Program to print GCD of given numbers
    By Bhavesh_seth in forum Software Development
    Replies: 5
    Last Post: 15-03-2011, 08:03 PM
  3. Need C program code to count numbers of negative & positive numbers
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 02:00 PM
  4. C sharp program to print random numbers
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 12:07 PM
  5. Program to print odd and even numbers
    By roodiii in forum Software Development
    Replies: 3
    Last Post: 30-11-2009, 02:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,688,031.91632 seconds with 17 queries