0% found this document useful (0 votes)
4 views1 page

C Programming Lab: Sorting Exercise

This lab exercise asks students to write a program that reads numbers from an input file into a dynamically allocated array, sorts the numbers using merge sort, and writes the sorted numbers to an output file. The program should prompt the user to enter the maximum number of inputs, allocate an array of that size, read numbers from the input file into the array until it reaches the end of the file or fills the array, sort the array using merge sort, and overwrite the output file with the sorted numbers. This is the last programming problem in C language for the semester.

Uploaded by

Samridh Kudesia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

C Programming Lab: Sorting Exercise

This lab exercise asks students to write a program that reads numbers from an input file into a dynamically allocated array, sorts the numbers using merge sort, and writes the sorted numbers to an output file. The program should prompt the user to enter the maximum number of inputs, allocate an array of that size, read numbers from the input file into the array until it reaches the end of the file or fills the array, sort the array using merge sort, and overwrite the output file with the sorted numbers. This is the last programming problem in C language for the semester.

Uploaded by

Samridh Kudesia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSC 001: Introduction to Computer Programming

2015-Jan-May Semester
Lab 8 (Deadline: Sunday, 5th April)

1. Sorting:
This exercise is to ensure that you have understood file input/output, dynamic memory
allocation, and sorting.
You should write a program that should ask the user for the maximum number of input
numbers, N. Now, you should allocate memory for an array of integers of size N.
Then you should open a file named [Link] and read one number at a time and store it in
the array. Stop reading when either you hit end-of-file, or when you have read N numbers.
(That is, the file may have less or more numbers than N.)
Then your program should sort the numbers in the array using merge sort.
Write the numbers in the sorted form to another file named, [Link].
If the file already exists, your program should overwrite it.
Maximum marks: 10
There is only one problem this week. This is the last problem in C language.

You might also like