Thread: Problem about an array program

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    3

    Problem about an array program

    Given a positive integer less than 10,000, write a C program that will find the largest possible number that can be formed by rearranging the digits of the number.

    Example:
    If i input: 2594
    The program must output: 9542
    This is my program and i don't know where's my error about printing the output. Can anyone help me?

    Code:
    #include <stdio.h>
    #include <math.h>
    
    char a[4],temp;
    int x,y,totl;
    
    main() {
    clrscr();
    printf("Input: ");
    scanf("%s",a);
    for(x=0;x<4;x++) {
    	for(y=x;y<4;y++) {
    		if(a[x]<a[y]) {
    		temp=a[x];
    		a[x]=a[y];
    		a[y]=temp;
    		}
    	}
    }
    printf("Output: %c\n",a);
    getch(); }
    Last edited by catatonicalvin; 12-11-2005 at 04:35 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. simple array of char array problem
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2006, 12:04 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM