Finding smallest number in a random array of numbers.
double smallestNum = Max +1
for(int i = 0; i< arraysize ; ++ i)
if (array[i]<smallestNum)
smallestNum=array[i]
return smallestNum
So, this makes sense to me how the code works but I am having trouble applying the concept to my code and I still haven't fully figured out how to generate the random number that I need for the specified range of 1-10000. The program is also using user defined functions as well so I confused on how to reference the the values entered for the previous integers to the sub function. >.<
Code I have so far:
#include <stdio.h>
#include <stdlib.h>
double mean(double ar[]);
double smallest(double ar[]);
double largest(double ar[]);
int main(void)
{
int seed;
double array[1000];
int arrIndex=0;
int max;
char chh;
{
//Prompts user to enter the value for integer "max".
max=0;
printf("\nEnter the upper bound: ");
fflush(stdin);
scanf("%d",&max);
//If statement checking that the value for max is greater than 10.
if (max <= 10)
{
printf("Upper bound should be %d greater than 10.",max);
fflush(stdin);
}
//If test passes, prompt user for the value of seed.
else{
printf("Enter the seed for random generation: ");
scanf("%d",seed);
}
//Incomplete
srand(seed);
for(arrIndex=1; arrIndex<=10000; ++arrIndex)
{
}
fflush(stdin);
scanf("%c", &chh);
return 0;
}}
//Function to find smallest number in array.
double smallest(double ar[])
{
int smallestNum=max + 1;
int i;
for (int i=0; i<arrIndex; ++ i)
{
smallest=array[i];
return smallestNum;
}
I will also have to find largest but I know it will be similar to the smallestNum function so no problems there, I just think my code organization is just crazy...
Thanks everyone.
PS: Student at SJSU, first time coding with C+, or coding period. lol.

