Click here to Skip to main content
15,907,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
#include <stdlib.h>
#include <stdio.h>
int main (){
int x,y,z;
scanf("%d%d%d",x,y,z);
if (x>y)
{
    if (x>z)
    {
        printf("%d",x);
        if (y>z)
        {
            printf("%d%d",y,z);
        }
        else
        {
            printf("%d%d",z,y);
        }
    }
    else
        printf("%d%d%d",z,x,y);
}
else
{
    if (y>z)
    {
        printf("%d",y);
        if (x>z)
        {
            printf("%d%d",x,z);
        }
        else
        {
            printf("%d%d",z,x);
        }
    }
    else
    {
        printf("%d%d%d",z,y,x);
    }
}
}



When I run this program it always tell me I have run into the wrong memory.
Posted
Updated 21-Jan-11 22:15pm
v2
Comments
Andrew Brock 22-Jan-11 4:16am    
Removed several unused <code> and <pre> tags from the end of the question

1 solution

You have to pass the parameters to scanf as pointers so it can write into the memory represented by the variable, not the memory represented by the variable value.

scanf("%d%d%d",&x,&y,&z);


EDIT:
On a side note, you probably want spaces in between each %d so you can enter the 3 numbers as 123 456 789
otherwise you have to separate the numbers by a line break like
123
456
789
 
Share this answer
 
v2
Comments
Espen Harlinn 22-Jan-11 4:34am    
Right Answer 5+
Sergey Alexandrovich Kryukov 22-Jan-11 6:05am    
Simple as that - my 5
zhaoyilong1 23-Jan-11 4:10am    
Thank you very much! I see where my fault is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900