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

Need help writing code for this. You should start out with a column of positive

ID: 3534923 • Letter: N

Question

Need help writing code for this.

You should start out with a column of positive and negative numbers in the A column of your spreadsheet.There should be 500 numbers in the column. You may generate these numbers using the function Your program should type (dim) all your variables. You will need at least three arrays in your program, each holding 500 values. Bring the values that you have generated in the first column in your spreadsheet into an array. Make a looping structure that goes through the array you have just generated. If the value of the array element is negative, put it into a new array that contains just negative values. If the value of the array element is positive, put it into a new array that just contains positive values. If it is 0, skip that value. At the end of this step you should have three arrays: the original array, an array containing all the positive values from the original array, and an array containing all the negative values from the original array. Keep track of the number of elements in the positive and negative arrays in two new variables. Sort each of the new arrays from largest to smallest absolute value in the array. A flowchart to accomplish this is attached. Display the sorted positive array in the B column in your spreadsheet. Display the sorted negative array in the C column in your spreadsheet. For whichever array has the fewest number of values, compare row by row the absolute values in each column (B and C). Keep track of the number of times the negative value is greater than the positive value (negative wins). Keep track of the number of times the positive value is greater than the negative value (positive wins). If there are more positive wins than negative wins from step 5, print out in the next column of the sheet (D) at the top of the column the phrase "More Positive Values" and in the cell under that the difference in the number of positive wins than negative wins. If there are more negative wins than positive wins, print out in the next column of the sheet at the top of the column the phrase "More Negative Values" and in the cell under that the difference in the number of negative wins and positive wine. If the number of negative and positive wins is the same, print out "It's a draw" at the top of the column.

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>


int main(){

int i =0;

FILE *fp = fopen("spreadsheet","w"); // opening a spreadsheet file to read create random numbers

for( i=0; i<500; i++){

fwrite(fp,"%d ",(rand() -10));

}

fclose(fp);

// reading the numbers into first array

int A[500];

FILE *fp1 = fopen("spreadsheet","r");

for( i=0; i<500; i++){

fscanf(fp,"%d",&A[i]);

}

// seperating positive and negative numbers

int positive[500], negative[500];

int p=0; n= 0;

for(i=0;i<500;i++){

if(A[i]<0){

negative[n] = a[i];

n++;

}

else if(A[i] >0){

positive[p] = a[i];

p++;

}

}

// here p+1 is the number of positive numbers in the array

// and n+1 is the number of negative numbers in the array

// soritng the negative array

int j =0;

for(i=0;i<n+1;i++){

for(j=i+1;j<n+1;j++){

if(negative[i]>negative[j]

temp=negative[i];

negative[i]=negative[j];

negative[j]=temp;

}

}

// sorting the positive array

for(i=0;i<p+1;i++){

for(j=i+1;j<p+1;j++){

if(positive[i]>positive[j]

temp=positive[i];

positive[i]=positive[j];

positive[j]=temp;

}

}

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote