Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jed/Pseudocode #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Jed/Pseudocode #1

wants to merge 1 commit into from

Conversation

Jeddy1git
Copy link

Reads in three numbers and writes them all in sorted order int main() { int n1, n2, n3;

//printf("Enter 3 numbers: "); scanf("%d %d %d", &n1, &n2, &n3);

// we'll store the numbers according to their order in these variables int lowest, middle, highest;

// n1 is the lowest number if (n1 <= n2 && n1 <= n3) { lowest = n1;

// figure out the remaining order between n2 and n3
if (n2 <= n3)
{
middle = n2;
highest = n3;
}
else
{
middle = n3;
highest = n2;
}
} // n2 is the lowest number else if (n2 <= n1 && n2 <= n3) { lowest = n2;

// figure out the remaining order between n1 and n3
if (n1 <= n3)
{
middle = n1;
highest = n3;
}
else
{
middle = n3;
highest = n1;
}
} // n3 is the lowest number else { lowest = n3;

// figure out the remaining order between n1 and n2
if (n1 <= n2)
{
middle = n1;
highest = n2;
}
else
{
middle = n2;
highest = n1;
}
}

printf("\n\n");

// output the numbers in ascending and descending order printf(" asc: %d %d %d\n\n", lowest, middle, highest); printf("desc: %d %d %d\n\n", highest, middle, lowest);

return 0; }

Reads in three numbers and writes them all in sorted order int main() { int n1, n2, n3;

//printf("Enter 3 numbers: "); scanf("%d %d %d", &n1, &n2, &n3);

// we'll store the numbers according to their order in these variables int lowest, middle, highest;

// n1 is the lowest number if (n1 <= n2 && n1 <= n3) { lowest = n1;

// figure out the remaining order between n2 and n3
if (n2 <= n3)
{
  middle = n2;
  highest = n3;
}
else
{
  middle = n3;
  highest = n2;
}
} // n2 is the lowest number else if (n2 <= n1 && n2 <= n3) { lowest = n2;

// figure out the remaining order between n1 and n3
if (n1 <= n3)
{
  middle = n1;
  highest = n3;
}
else
{
  middle = n3;
  highest = n1;
}
} // n3 is the lowest number else { lowest = n3;

// figure out the remaining order between n1 and n2
if (n1 <= n2)
{
  middle = n1;
  highest = n2;
}
else
{
  middle = n2;
  highest = n1;
}
}

printf("\n\n");

// output the numbers in ascending and descending order printf(" asc: %d %d %d\n\n", lowest, middle, highest); printf("desc: %d %d %d\n\n", highest, middle, lowest);

return 0; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant