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

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...
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.
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:...
I'm trying to do some pratice problems in the book and here is one of them....
I'm trying to do some pratice problems in the book and here is one of them. THIS IS FOR JAVA. Write a method cleanCorruptData that accepts an ArrayList of integers and removes any adjacent pair of integers in the list if the left element of the pair is smaller than the right element of the pair. Every pair's left element is an even-numbered index in the list, and every pair's right element is an odd index in the list. For...
Write a program that reads a file line by line, and reads each line’s tokens to...
Write a program that reads a file line by line, and reads each line’s tokens to create a Student object that gets inserted into an ArrayList that holds Student objects.  Each line from the file to read will contain two strings for first and last name, and three floats for three test grades.  After reading the file and filling the ArrayList with Student objects, sort the ArrayList and output the contents of the ArrayList so that the students with the highest average...
Create a program that generates random number between 0 and 50 and puts them into a...
Create a program that generates random number between 0 and 50 and puts them into a linked list. When it generates 49, instead of adding it to the list, it prints the list, freeing each node and then exits. Submit your .c file
Write a program that reads a file (provided as attachment to this assignment) and write the...
Write a program that reads a file (provided as attachment to this assignment) and write the file to a different file with line numbers inserted at the beginning of each line. Such as Example File Input: This is a test Example File Output 1. This is a test. (Please comment and document your code and take your time no rush).
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
I am trying to create a program that reads from a csv file and finds the...
I am trying to create a program that reads from a csv file and finds the sum of total volume in liters of liquor sold from the csv file by county and print that list out by county in descending order. Currently my program runs and gives me the right answers but it is not in descending order. I tried this:     for county, volume in sorted(sums_by_volume.items(), key=lambda x: x[1], reverse=True):         index +=1         print("{}. {} {:.2f}".format(county, sums_by_volume[county]))      When I run...
Write a program that reads an integer, a list of words, and a character.
13.14 LAB: Contains the characterWrite a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character.Ex: If the input is:4 hello zoo sleep drizzle zthen the output is:zoo drizzleIn c++ 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT