Results 1 to 3 of 3

Thread: Write a code for to print grouping of numbers

  1. #1
    CoxWatson is offline Senior Member
    Join Date
    Dec 2009
    Posts
    232
    Rep Power
    3

    Default Write a code for to print grouping of numbers

    I am first year computer science student. Currently I am learning C language. I am trying to write C code for to print the combination of given numbers. If you have the example for this number combinations then please give me that. Please reply me as soon as possible.

  2. #2
    BrooksGray is offline Senior Member
    Join Date
    Dec 2009
    Posts
    231
    Rep Power
    3

    Default

    Try out this code, when you run this program you get the Combination of numbers as a output result:

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,j,k,l,m;
    clrscr();
    for(i=0;i<4;i++)
    {
    for(j=i+1;j<=4;j++)
    {
    printf("%d",j);
    }
    for(k=1;k<=i;k++)
    {
    printf("%d",k);
    }
    printf("n");
    for(k=i;k>=1;k--)
    {
    printf("%d",k);
    }
    for(j=4;j>=i+1;j--)
    {
    printf("%d",j);
    }
    getch();
    }

  3. #3
    CruzPowell is offline Senior Member
    Join Date
    Dec 2009
    Posts
    224
    Rep Power
    3

    Default

    Try this:

    Code:
    # include <stdio.h>
    # include <conio.h>
     
    /* Function to swap values at two pointers */
    void swap (char *x, char *y)
    {
        char temp;
        temp = *x;
        *x = *y;
        *y = temp;
    }
     
    void permute(char *a, int i, int n)
    {
       int j;
       if (i == n)
         printf("%sn", a);
       else
       {
            for (j = i; j <= n; j++)
           {
              swap((a+i), (a+j));
              permute(a, i+1, n);
              swap((a+i), (a+j)); //backtrack
           }
       }
    }
     
    /* Driver program to test above functions */
    int main()
    {
       char a[] = "ABC";
       permute(a, 0, 2);
       getchar();
       return 0;
    }

Similar Threads

  1. C code for print odd numbers and their average
    By Lily Chauchoin in forum Programming
    Replies: 2
    Last Post: 07-30-2010, 09:17 PM
  2. Print grouping of numbers in C
    By CoxWatson in forum Programming
    Replies: 1
    Last Post: 03-27-2010, 01:27 PM
  3. C# program to print random numbers
    By Garcíarobine in forum Programming
    Replies: 2
    Last Post: 01-13-2010, 05:47 PM
  4. Grouping of active application
    By Fred Morgan in forum Applications
    Replies: 0
    Last Post: 07-15-2009, 01:19 PM
  5. Creating And Grouping Objects in phun
    By hassik54 in forum Everything Else
    Replies: 0
    Last Post: 05-21-2008, 12:52 PM

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
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48