Hi, I\'d like to ask on how to finish this. I\'m having a hard time on 4,5,6,7.
ID: 3859963 • Letter: H
Question
Hi, I'd like to ask on how to finish this. I'm having a hard time on 4,5,6,7. I've attached here my progress so far:#include <stdio.h> #include <stdlib.h>
int pivot(int *array, int size) { int a,b;
a=size%2; b=size/2;
return b; }
int hh(int *array,int size) { int i,index; index=pivot(array,size); for(i=index;i<size;i++) { if (array[i]>array[index]) printf("%d, ",array[i]); } }
int hl(int *array,int size) { int i,index; index=pivot(array,size); for(i=index;i<size;i++) { if (array[i]<array[index]) printf("%d, ",array[i]); } }
int lh(int *array,int size) { int i,index; index=pivot(array,size); for(i=0;i<index;i++) { if (array[i]>array[index]) printf("%d, ",array[i]); } }
int ll(int *array,int size) { int i,index; index=pivot(array,size); for(i=0;i<index;i++) { if (array[i]<array[index]) printf("%d, ",array[i]); } }
int newl(int *array,int size) { int i,index; index=pivot(array,size); hl(array,size); ll(array,size); }
int newh(int *array,int size) { int i,index; index=pivot(array,size); hh(array,size); lh(array,size); }
int main() { int a,i,length,array[20],index;
printf("Input array length: "); scanf("%d",&length); printf(" "); for(i=0;i<length;i++) { printf("input[%d]: ",i); scanf("%d",&array[i]); } index=pivot(array,length); printf(" index = %d, ",index); printf("input[%d] = %d ",index,array[index]); printf(" a. High Index High Value: [ "); hh(array,length); printf("]"); printf(" b. High Index Low Value: [ "); hl(array,length); printf("]"); printf(" c. Low Index High Value: [ "); lh(array,length); printf("]"); printf(" d. Low Index Low Value: [ "); ll(array,length); printf("]"); printf(" e. New Low Index: [ "); newl(array,length); printf("]"); printf(" f. New High Index: [ "); newh(array,length); printf("]"); }
Drive 00 12:52 PM Laboratory Activity 6: Functions Ask for the user to input a variable-length array Initialize an output array that has the same size with input array Create a function that finds and returns the middle index of an array. If the number of elements is even, then return the nearest index of higher value from the middle. We will call it as the pivot index. 1. 2. 3. 4. Mystery Function => Using the value of the middle index as in #1, create a new sets of function such that it returns HighindexHighValArr=> all values of the succeeding indices shall be compared to the value of the middle index. This array contains the values that are higher than the value of the middle index. HighlndexLowValArr => all values of the succeeding indices shall be compared to the value of the middle index. This array contains the values that are lower than the value of the middle index a. b. C. LowlndexHighValArr => all values of the preceding indices shall be compared to the value of the middle index This array cnntains the
Explanation / Answer
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
int pivot(int *array, int size)
{
int a,b;
a=size%2;
b=size/2;
return b;
}
int hh(int *array,int size)
{
int i,index;
index=pivot(array,size);
for(i=index;i<size;i++)
{
if (array[i]>array[index])
printf("%d, ",array[i]);
}
}
int hl(int *array,int size)
{
int i,index;
index=pivot(array,size);
for(i=index;i<size;i++)
{
if (array[i]<array[index])
printf("%d, ",array[i]);
}
}
int lh(int *array,int size)
{
int i,index;
index=pivot(array,size);
for(i=0;i<index;i++)
{
if (array[i]>array[index])
printf("%d, ",array[i]);
}
}
int ll(int *array,int size)
{
int i,index;
index=pivot(array,size);
for(i=0;i<index;i++)
{
if (array[i]<array[index])
printf("%d, ",array[i]);
}
}
int newl(int *array,int size)
{
int i,index;
index=pivot(array,size);
hl(array,size);
ll(array,size);
}
int newh(int *array,int size)
{
int i,index;
index=pivot(array,size);
hh(array,size);
lh(array,size);
}
int newoutput(int *array,int size)
{
int i,index;
index=pivot(array,size);
for(i=0;i<size;i++)
{
if (i==index)
printf("%d, ",array[i]);
else
printf("%d, ",0);
}
}
int main()
{
int a,i,length,array[20],index;
printf("Input array length: ");
scanf("%d",&length);
printf(" ");
for(i=0;i<length;i++)
{
printf("input[%d]: ",i);
scanf("%d",&array[i]);
}
index=pivot(array,length);
printf(" index = %d, ",index);
printf("input[%d] = %d ",index,array[index]);
printf(" a. High Index High Value: [ ");
hh(array,length);
printf("]");
printf(" b. High Index Low Value: [ ");
hl(array,length);
printf("]");
printf(" c. Low Index High Value: [ ");
lh(array,length);
printf("]");
printf(" d. Low Index Low Value: [ ");
ll(array,length);
printf("]");
printf(" e. New Low Index: [ ");
newl(array,length);
printf("]");
printf(" f. New High Index: [ ");
newh(array,length);
printf("]");
printf(" g. Output Array: [ ");
newoutput(array,length);
printf("]");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.