Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a program that will input numeric data type double into an array. Do this

ID: 3809883 • Letter: D

Question

Design a program that will input numeric data type double into an array. Do this function by designing a function called inputData. Then the program should sort the data and display the whole content of the array. Sort the array by using bubble sort (you can Google that/or use the qsort function) and design a separate function (call it displayArray) to display the contents of the array. Your program should include: proper case, variable names(meaningful and use conventions) proper organization, indentation, white space, and comments Has the right inputs and outputs, computes correct results. is efficient Use a loop that gives the user the option of do another calculation or quit. Submit the .c file

Explanation / Answer

#include <stdio.h>

void inputData(double arr[], int size);// method to get input from the user
void displayArray(double arr[], int size);// method to display the array
void bubbleSort(double arr[], int size);// method to do the bubble sort

int main() {
double array[100];// array
int n;// size of the array
printf("Enter number of elements");
scanf("%d", &n);//reading the size of the array

printf("Enter %d integers ", n);
inputData(array, n);//calling inputData

bubbleSort(array, n);//calling bubbleSort

printf("Sorted list in ascending order: ");
  
displayArray(array, n);//calling displayArray

return 0;

}

void inputData(double arr[], int size) {
int c;
for (c = 0; c < size; c++)
scanf("%lf", & arr[c]);
}

void displayArray(double arr[], int size) {
int c;
for (c = 0; c < size; c++)
printf("%.2lf ", arr[c]);
}

void bubbleSort(double arr[], int size) {
long c, d, t;

for (c = 0; c < (size - 1); c++) {
for (d = 0; d < size - c - 1; d++) {
if (arr[d] > arr[d + 1]) {
/* Swapping */

t = arr[d];
arr[d] = arr[d + 1];
arr[d + 1] = t;
}
}
}
}

-----------------output---------------

Enter number of elements5                                                                                                                                                       

Enter 5 integers                                                                                                                                                                

10                                                                                                                                                                              

12                                                                                                                                                                              

5                                                                                                                                                                               

3                                                                                                                                                                               

9                                                                                                                                                                               

Sorted list in ascending order:                                                                                                                                                 

3.00                                                                                                                                                                            

5.00                                                                                                                                                                            

9.00                                                                                                                                                                            

10.00                                                                                                                                                                           

12.00

-------------output ends--------------

Note: Feel free to ask question in case of any doubt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote