Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C program that tests whether two sequences of positive numbers are orde

ID: 3887638 • Letter: C

Question

Create a C program that tests whether two sequences of positive numbers are order equivalent.

Two sequences a and b are order equivalent if they have the same number of elements and

they both contain less than two numbers or if for all where n is the length of a sequence

Examples of order equivalent sequences:

7 5 9 13 12 and 4 2 25 33 26

12 and 8

The program must accept the two sequences with no separator between the two. If the number of numbers accepted is n, the first n/2 numbers are assumed to be in the first sequence and the rest form the second sequence. The program must then check the sequences for order equivalence and print the result. You can assume that the maximum size of the two sequences is 100. You need to use 0 or any negative number to mark the end of the sequence.

Please remember to organize the code as below:

Have two functions besides main:

one that accepts the two sequences and

the other that checks for order equivalence and returns an integer depending on the test

The main function prints the message for the user.

You cannot use any global variables.

Explanation / Answer

#include<stdio.h>
int create(int[100]);
int check(int[100],int n)
int main() {
int user_input[100];
int array_length=0,result=0;
printf("Enter the elements of array ");
printf("Enter negative number to stop ");
array_length=create(user_input);
printf("%d",array_length);
result=check(user_input,array_length);
if(result !=(-1))
{
printf("Sets are order equivalent");
}
else
{
printf("Sets are not order equivalent");
}
}
//Function to take input
int create(int user_input[100])
{
int i=0,input=0,check=1;
  
do
{
printf(" ");
scanf("%d",&input);
check=input;
if(check>0)
{
user_input[i]=input;
i++;
}
}while((i<100) && (check>0));
return(i);

}


//Function to compare sets
int check(int user_input[100],int array_length)
{
int result=0;
int seq1[100],seq2[100];
if((array_length)%2 != 0)
{
result=-1;
}
else if(array_length==2)
{
  
}
else
{
mid=(array_length/2);
for(i=0;i<mid;i++)
{
seq1[i]=user_input[i];
}
int j=0;
for(i=mid;i<array_length;i++)
{
seq2[j]=user_input[i];
j++;
}
  
for(int i = 0; i < mid; i++)
{
int curRank = 0;
  
for (j = 0; j < i; j++)
{
  
if (seq1[i] > seq1[j])
{
curRank++;
}
else
{
rank1[j]++;
}
}
  
rank1[i] = curRank;
}
  
for(int i = 0; i < mid; i++)
{
int curRank = 0;
  

for (j = 0; j < i; j++)
{
  
if (seq2[i] > seq2[j])
{
curRank++;
}
else
{
rank2[j]++;
}
}
  
rank2[i] = curRank;
}
  
  
for(i=0;i<mid;i++)
{
if(rank1[i]!=rank2[i])
{
result=-1;
}
  
}
  
}
return(result);
}