Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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(" 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

What are the three phases of intermediate planning?

Answered: 1 week ago

Question

3. Test complex thinking, not just skills and factual knowledge.

Answered: 1 week ago

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago