Related questions
Write in C Language.
Make any program regarding data input, save data, read data, search data and sort data (file, sorting and searching)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
// write data input numbers to file
FILE* wfptr;
wfptr = fopen("file.txt", "w");
if (wfptr == NULL) {
printf("ERROR");
exit(1);
}
for (int i = 0; i < 5; i++) {
int val;
scanf("%d", &val);
// storing data to file
fprintf(wfptr, "%d ", val);
}
// closing the file
fclose(wfptr);
// data type for calculating time
clock_t starttime, endtime;
// variable for calculating total time of execution
double totaltime;
int i = 0, j, n = 0, min, index;
// declaring array
int arr[5];
// declaring file pointer
FILE* fptr;
// opening the integer file.
fptr = fopen("file.txt", "r");
// scanning integer from file to array
while (fscanf(fptr, "%d", &arr[i]) == 1)
{
// count elements from file //
n++;
i++;
}
starttime = clock();
printf("start time to sort : %f\n", (float)starttime);
// sort data
for (i = 0; i < n - 1; i++) {
min = arr[i];
for (j = i + 1; j < n; j++) {
if (arr[j] < min) {
min = arr[j];
index = j;
}
}
int temp = arr[i];
arr[i] = min;
arr[index] = temp;
}
// selection sort logic ends here
// calculating clock when sorting ends
endtime = clock();
printf("%f\n", (float)endtime);
totaltime = ((double)(endtime - starttime)) / CLOCKS_PER_SEC;
// printing the sorted array...
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n\nendtime after sort: %f\n", (float)endtime);
printf("\n\ntotal time of execution = %f", totaltime);
return 0;
}
Step by stepSolved in 2 steps with 1 images
- Java/Data Structures: Adding entries to the end of a list does not change the positions of entries already in the list. (True or False)arrow_forwardWhat does "scope" mean when referring to software?arrow_forwardComputer Programs: In this section, we'll go further into each of the four memory allocation techniques we've seen so far in the course and describe how they work. How frequently do each of these four terms really get used in practice?arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY