When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
3 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
dd
#include <stdio.h>
#define ARRAY_SIZE 10
void bubbleSort(int integer[], int size){
int ordered = 0; //Important to condition the do-while loop.
int temp = 0; //Temporary variable required to swap two integers in the array.
do { //Invites the code to run this body once, and gets trapped into a loop if while (condition) is true.
ordered = 0; //Closes the while loop, unless it enters the if function.
for (int i=0; i < 9; i++)
if (integer[i] > integer[i + 1]) {
temp = integer[i];
integer[i] = integer[i + 1];
integer[i + 1] = temp;
ordered = 1; //successfully ordered! This opens the while loop to rerun the ordering sequence until it is over.
}
} while (ordered);
}
int calculateSum(int integers[], int count) {
int sum = 0;
for (int i = 0; i<count; i++) {
sum += integers[i];
}
return sum;
}
int calculateAverage(int sum, int count) {
return sum/count;
}
int calculateMedian(int integers[]){
int median = 0;
median = (integers[0]+integers[9])/2;
printf("Median: %f\n", median);
return median;
}
int main() {
int integers[ARRAY_SIZE];
int count = 0;
int remainder = 10;
int minimum = 0;
int maximum = 0;
int sum = 0;
float average = 0;
float median;
float median1 = 0;
float median2 = 0;
printf("Hello! Please write your 10 integers: ");
for (int i = 0; i < ARRAY_SIZE; i++) {
scanf("%i", &integers[i]);
printf("You wrote %i! %i integers remaining...\n", integers[i], remainder-1);
remainder--;
count++;
}
......