Question

In: Computer Science

I'm trying to write a program that reads 3 heights of kids and puts them in...

I'm trying to write a program that reads 3 heights of kids and puts them in ascending order using if and else statements but i'm having trouble

#include<stdio.h>
int main()
{
int k1,k2,k3;
printf("Enter height of kid #1 >");
scanf("%d",&k1);
printf("Enter height of kid #2 >");
scanf("%d",&k2);
printf("Enter height of kid #3 >");
scanf("%d",&k3);
if(k3>k2>k1)
{
printf("In ascending order %d %d %d",k3,k2,k1);
}
else if(k3>k1>k2)
{
printf("In ascending order %d %d %d",k3,k1,k2);
}
else if(k2>k3>k1)
{
printf("In ascending order %d %d %d",k2,k3,k1);
}
else if(k2>k1>k3)
{
printf("In ascending order %d %d %d",k2,k1,k3);
}
else if(k1>k3>k2)
{
printf("In ascending order %d %d %d",k1,k3,k2);
}
else if(k1>k2>k3)
{
printf("In ascending order %d %d %d",k1,k2,k3);
}
}

Solutions

Expert Solution

#include<stdio.h>

int main() {
    int k1, k2, k3;
    printf("Enter height of kid #1 >");
    scanf("%d", &k1);
    printf("Enter height of kid #2 >");
    scanf("%d", &k2);
    printf("Enter height of kid #3 >");
    scanf("%d", &k3);
    if (k3 <= k2 && k2 <= k1) {
        printf("In ascending order %d %d %d", k3, k2, k1);
    } else if (k3 <= k1 && k1 <= k2) {
        printf("In ascending order %d %d %d", k3, k1, k2);
    } else if (k2 <= k3 && k3 <= k1) {
        printf("In ascending order %d %d %d", k2, k3, k1);
    } else if (k2 <= k1 && k1 <= k3) {
        printf("In ascending order %d %d %d", k2, k1, k3);
    } else if (k1 <= k3 && k3 <= k2) {
        printf("In ascending order %d %d %d", k1, k3, k2);
    } else if (k1 <= k2 && k2 <= k3) {
        printf("In ascending order %d %d %d", k1, k2, k3);
    }
    return 0;
}

Related Solutions

I'm trying to write a feet to meters and centimeters program and I'm looking for a...
I'm trying to write a feet to meters and centimeters program and I'm looking for a little help so I can see how close I got. It should do the following: Write a convertToMetric class that has the following field: standard - holds a double, standard length value in feet. The class should have the following methods: Constructor - that accepts a length in feet (as a double) and stores it in the standard field. setStandard - accepts a standard...
Write a MIPS assembly program that reads 3 add them together and stores the answer in...
Write a MIPS assembly program that reads 3 add them together and stores the answer in memory.
MIPS Program I'm trying to write a program that will take in two numbers from the...
MIPS Program I'm trying to write a program that will take in two numbers from the user and output the sum at the end. However, I keep getting very wrong answers. For example, I add 2 and 2 and get 268501000. Help would be appreciated. .data #starts data use userIn1:    .word 4 #sets aside space for input    userIn2:    .word 4 #sets aside space for input total:    .word 4 #sets space aside for input    request:   ...
Write a Java program that reads two integers on the keyboard and displays them on the...
Write a Java program that reads two integers on the keyboard and displays them on the screen.
Write a program that reads the letter codes of a telephone number pad and converts them...
Write a program that reads the letter codes of a telephone number pad and converts them into their corresponding number patterns. a.        One acceptable form of output: Sample input:              Sample Output: 800-MATTRESS 800-628-8737 (leave off the last “S”) 800-mattress                800-628-8737 (leave off the last “S”) Another acceptable form of output: Sample input:              Sample Output:             8   8 0   0   0 0    M 6 A 2 T                                8 T                                8 R                                7 E                                 3 S                                 7 The letters ‘A’ to ‘Z’ and ‘a’ to...
Write a C program that reads three integers and then prints them in the order read...
Write a C program that reads three integers and then prints them in the order read and reversed. Use four functions: main, one to read the data, one to print them in the order read, and one to print them reversed.
Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them...
Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them into Turtle commands, and then executes them. The codes are in a Python list, passed as an argument to your function. turtleRunner(t, x) t is a Turtle x is a list of Turtle commands Code List (f, d)    Move forward by d pixels u Lift pen up d Put pen down (l, d) Turn left by d degrees (r, d) Turn right by...
Hi. I'm trying to write a program that uses dynamic memory management to create two arrays....
Hi. I'm trying to write a program that uses dynamic memory management to create two arrays. splice() must create the third array and return a pointer to main(). Main() must capture the pointer returned from the splice() function. Sol'n so far, I get the results of the first and second array, but it isn't showing the results of the spliced function: #include <iostream> using namespace std; // Function int* splice() inserts the 2nd array into 1st array starting at int...
I'm working on a to-do list program in Python 2. I'm trying to delete an item...
I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue:...
Write a program that reads numbers from scanf1 (keyboard) and then sums them, stopping when 0...
Write a program that reads numbers from scanf1 (keyboard) and then sums them, stopping when 0 has been entered. Construct three versions of this program, using the while, do-while, and for loops.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT