I'm trying to take a users input and break it up into four separate numbers, then take those numbers and arrange them from smallest to largest.
So far I can't seem to get them working right, and i'm running out of ideas if anyone could give me an idea, or even a nudge in the right direction, I would greatly appreciate it.
Code:
# include <stdio.h>main ()
{
int inputVariables[4]; //where userinput goes after being broken up
int arrangedValues [4];// the user values arranged lowest to highest
int i;
int j;
int userInput;
int remainders; //used to break up input
int numberX; // users input arranged forwards
int numberY; // users input arranged forwards
printf ("Please state a number from 1000 - 9999, excluding numbers with four identical digits i.e 9999 \n");
scanf (" %d",&userInput);
remainders = userInput % 1000;
inputVariables[0] = userInput / 1000;
userInput = remainders;
remainders = userInput % 100;
inputVariables[1] = userInput / 100;
userInput = remainders;
remainders =userInput % 10;
inputVariables[2] = userInput / 10;
userInput = remainders;
inputVariables[3] = remainders;
printf ("%d \n",inputVariables[0]);
printf ("%d \n",inputVariables[1]);
printf ("%d \n",inputVariables[2]);
printf ("%d \n",inputVariables[3]);
printf ("%d \n", remainders);
do
{
for (i = 0 ; i < 4; i++)
{
for (j = 0 ; j < 4; j++)
{
if (inputVariables[i] < inputVariables[j])
{
arrangedValues[i] = inputVariables[j];
}
}
}
}
while (arrangedValues[0] >= arrangedValues[1] >= arrangedValues[2] >= arrangedValues[3]);
printf(" %d %d %d %d \n",arrangedValues [0],arrangedValues [1],arrangedValues [2],arrangedValues [3]);
printf(" %d %d %d %d \n",arrangedValues [3],arrangedValues [2],arrangedValues [1],arrangedValues [0]);
}