Question: #include stdio.h #include stdlib.h #include typedef struct { unsigned long time; double degrees; } TemperatureReading; // This is a C-Program that works with temperature reading

#include "stdio.h"

#include "stdlib.h"

#include

typedef struct {

unsigned long time;

double degrees;

} TemperatureReading;

// This is a C-Program that works with temperature reading objects. The

// TemperatureReading struct has two properties, time and degrees. In main we have an

// array of readings taken throughout a day. Currently, the array lists the readings

// in chronological order staring at '0L' and ending at '600L'.

// OBJECTIVE: sort the temperature readings from lowest temperature to highest temperature.

// In this case we are interested in degrees, so the final result should print:

//readings:

//{ 50, 31.000000 }

//{ 0, 32.000000 }

//{ 100, 33.000000 }

//{ 150, 34.000000 }

//{ 600, 35.000000 }

//{ 200, 37.000000 }

//{ 550, 38.000000 }

//{ 350, 39.000000 }

//{ 500, 41.000000 }

//{ 450, 42.000000 }

//{ 400, 44.000000 }

int main()

{

TemperatureReading readings[] =

{

{ 0L, 32.0 },

{ 50L, 31.0 },

{ 100L, 33.0 },

{ 150L, 34.0 },

{ 200L, 37.0 },

{ 350L, 39.0 },

{ 400L, 44.0 },

{ 450L, 42.0 },

{ 500L, 41.0 },

{ 550L, 38.0 },

{ 600L, 35.0 }

};

// TODO: sort the array of temperature readings by the degrees such that

// they are in order from lowest to highest

// i.e: [ { 50L, 31.0}, { 0L, 32.0 }, { 100L, 33.0 }, ... ]

// print out the values

printf("readings: ");

for (unsigned int i = 0; i < 11; ++i)

{

printf("{ %d, %f } ", readings[i].time, readings[i].degrees);

}

getchar();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!