Question
Hello I need help with this coding project in C TASK: Start with the baseline project attached to this assignment sorting.zip. Change the existing code
Hello I need help with this coding project in C
TASK: Start with the baseline project attached to this assignment sorting.zip. Change the existing code to re-ask the user for input on this condition: scanf("%d",&n); if (n > 30) return 1; Instead of return 1, keep the user in a loop until a number <= 30 is entered.
REQUIREMENTS: Make sure your changed version of the program runs properly with no syntax errors or run time errors. The complete program source code and project files/directories must be uploaded to blackboard as a zip file only, no rar please. I cannot grade a program unless it runs within the CodeBlocks environment on my local PC. Please don't move the project to a different IDE and then attempt to move it back to CodeBlocks unless you can do that very carefully. I need to grade these quickly in CodeBlocks.
Code:
(Main.c)
#include
int main() { int data[30],n,i;
printf("Number of items to sort ? (less than 30 please) : "); scanf("%d",&n); if (n > 30) return 1;
printf("Enter each value followed by CR :");
for( i = 0; i < n; i++ ) scanf("%d", &data[i]);
mergesort(data,0,n-1);
printf(" Sorted array is :"); for( i = 0; i < n; i++ ) printf("%d ", data[i]);
return 0; }
void mergesort( int data[], int liststart, int listend) { int mid;
if( liststart < listend ) { mid = ( liststart + listend ) / 2; mergesort ( data, liststart, mid ); mergesort ( data, mid+1, listend ); merge ( data, liststart, mid, mid+1, listend ); } }
void merge( int data[], int list1start, int list1end, int list2start, int list2end) { int temp[50]; int i,j,k; i=list1start; j=list2start; k=0;
while( ( i <= list1end) && (j <= list2end) ) { if(data[i] < data[j]) temp[k++] = data[i++]; else temp[k++] = data[j++]; }
while (i <= list1end) temp[k++] = data[i++];
while( j <= list2end) temp[k++] = data[j++];
for( i = list1start, j=0; i <= list2end; i++,j++) data[i] = temp[j]; }
(Proto.h)
void mergesort(int data[], int liststart, int listend); void merge(int data[], int list1start, int list1end, int list2start, int list2end);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started