Home / Expert Answers / Computer Science / hello-i-need-help-with-this-coding-project-in-c-task-start-with-the-baseline-project-attached-to-pa625

(Solved): Hello I need help with this coding project in C TASK: Start with the baseline project attached to ...



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 <stdio.h>
#include "proto.h"

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("\nSorted 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);



We have an Answer from Expert

View Expert Answer

Expert Answer


You can modify the main() function to loop until the user enters a number less than or equal to 30. Here is an example of how you could do it:int main
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe