Question

How do you write the code for a program to compare three variable int's in a...

How do you write the code for a program to compare three variable int's in a void function with if/else statements only. The program takes 3 integers as input and outputs the integers sorted from least to greatest. Cannot use && or ||, only basic nested if/else statements. Please give details.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

below i written the C code as per the requirement.

Please note the below program has been tested on ubuntu 16.04 system and compiled using gcc compiler. This code will also work on other iDe;'

-----------------------------------------------------------------------------------------------------------------------------------

Program:

-----------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

void swap(int *x, int *y);

void compare(int a, int b,int c)

{

if (a > c)
{

swap(&a, &c);

}

if (a > b)
{

swap(&a, &b);

}

if (b > c)
{
swap(&b, &c);
}

printf("Numbers before sorting = %d %d %d\n", a, b, c);

}

void swap(int *x, int *y)

{

int temp;

temp = *x;

*x = *y;

*y = temp;

}

int main()

{

int a, b, c;

printf("Enter three numbers: ");

scanf("%d %d %d", &a, &b, &c);

printf("Numbers before sorting = %d %d %d\n", a, b, c);

compare(a, b, c);

return 0;

}

================================================================

Output:

=================================================================

Kindly Check and Verify Thanks..!!!

Add a comment
Know the answer?
Add Answer to:
How do you write the code for a program to compare three variable int's in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • help please! due tomorrow! Write code in Java Write a program that takes as input an...

    help please! due tomorrow! Write code in Java Write a program that takes as input an unordered list of integers, creates a Btree of minimum degree t 4 and then outputs the sorted list of integers. A simple inorder traversal of the B tree will output the list of the integers in a increasing order. You can choose your programming language and the platform you run on. The documentation is required for any programming assignment.

  • Please solve this C language progrm (2-D Array program) the most basic way ! Thank You!...

    Please solve this C language progrm (2-D Array program) the most basic way ! Thank You! Write a function that takes a 4 x 4 array of integers as its parameter. The function must use two nested for-loops to determine the largest integer in the array as well as its row and column numbers. Recall that C-functions cannot return multiple values. Use pointers in the function parameter list to relay the results to the caller program. Write another function, which...

  • Write a C program for the following requirement, thank you! Write a program that takes three...

    Write a C program for the following requirement, thank you! Write a program that takes three composite (Non-prime) positive integers from the user and computes their greatest common divisor (gcd).

  • please write program in C++ Write a function called productEven, that takes as its parameter an...

    please write program in C++ Write a function called productEven, that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function. please write the program in C++

  • C++ Write a program that reads three positive integers (> 0) from the command line (one...

    C++ Write a program that reads three positive integers (> 0) from the command line (one at a time), then computes and prints the smallest entered number. Use if-else statements for three integer comparison. Example: Enter an integer: 5 Enter an integer: 23 Enter an integer: 7 The smallest number is: 5 Example 2: Enter an integer: 3 Enter an integer: 3 Enter an integer: 6 The smallest number is: 3 "The input must be positive number. The program should...

  • Write a C program, named sortit, that reads three integers from the command line argument and...

    Write a C program, named sortit, that reads three integers from the command line argument and returns the sorted list of the integers on the standard output screen, For instance, >sortit 3 5 7 >The sorted list is 3, 5, 7. >sortit 4 0 9 >The sorted list is 0, 4, 9 >sortit 1 p 9 >sortit: invalid input p. >sortit >usage: sortit num1 num2 num3! 1. The source code of a c file 2. Screenshots that show successful execution...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Write a program that prompts the user to input three different integers from the keyboard, then...

    Write a program that prompts the user to input three different integers from the keyboard, then prints the sum, the average, and the product. The screen dialogue should appear exactly as follows: Enter three different integers: 13 27 14 Sum is 54 Average is 18 Product is 4914 Please code in c program

  • Write a complete C++ program that at least consists of the main() function and a recursive...

    Write a complete C++ program that at least consists of the main() function and a recursive function gcd() with return value. Define function gcd() with two and only two parameters that calculates the greatest common divider of two given parameters. Hint: use the difference between two parameters or the remainder obtained using one parameter divide the other. In main() Read 2 positive integers with proper prompt. Call gcd() with proper syntax. Display the result, i.e. the greatest common divider of...

  • C++ program Please only (if) (else) statements No while statements use Write a program that takes...

    C++ program Please only (if) (else) statements No while statements use Write a program that takes rate and outputs the employee's wages for the week input employee's hours worked and regular pay as an Calculate employee's wages as follows: She receives her regular rate for the an first 40 hours, 1.5 times her regular rate for each hour between 40 and 50 hours, and double her regular rate for each hour over 50. For invalid inputs, in addition to outputting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT