Here's most of my program.
program is create a random generated array of 50 elements
elements are values 1-500
read_array function initializes new array of integers each time
print_array function prints current array after stopping program with entry of -1 from keyboard /// have no idea how to code this
Two_largest function takes array from read_array function and finds the two largest element values
finally the main() function is to print these values
(1) i do not know if the two largest values are to be printed for each and every array created before -1 stops program
and if so, how could you print out say
(2) what kind of code is used to scan in a -1 to stop program
-- my friend says that control-Z is used commonly, and
there is an ASCII code for that -- what is this???
(3) the whole program is to be one DO/WHILE Loop, I didn't know where to put that in the main() ; but assume it has something to do with the -1 stoppage component
(4) what are the int values for each function doing??? (the no-array and non-pointer int values is what I refer to here.)
Code:
/* Two largest integers */
/* stop when -1 entered */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_ELEM 50
#define RANDOM_NUM 500
void Two_largest(int array2[], int m, int *lg, int *lg2);
void read_array(int array1[], int r);
void print_array(int array3[], int p);
srand (time(NULL));
main()
{
int a, b, c;
int read[NUM_ELEM]={0};
int print[NUM_ELEM]={0};
int sortedarray[NUM_ELEM]={0};
int *largest;
int *secondlargest;
read_array(read,a);
print_array(print,b);
Two_largest(sortedarray, c, *largest, *secondlargest);
printf("%d %d\n", &largest, &secondlargest);
}
read_array(int array1[], int r)
{
int i;
for (i=0; i<NUM_ELEM; i++)
{
array1[i]=rand()%RANDOM_NUM+1;
}
}
print_array(int array3[], int p)
{
int i;
for (i=0; i<NUM_ELEM; i++)
void Two_largest(int array2[], int m, int *lg, int *lg2)
{
int i,j;
for (i=o; i<NUM_ELEM; i++)
{
for (j=i+1; j<NUM_ELEM; j++)
{
temp = array2[i];
array2[i] = array2[j];
array2[j] = temp;
}
}
*lg = array2[j];
*lg2 = array2[j-1];
}