thanx i fixed the error but still has a warning says ( s has been used but never given a value) i know that s should be the size of the arry 'a' but i dunno how can i assign a value for s . also when i run my programe i got a small error window saying
access violation the instraction to address 00401216 attampted to read from location 03713000
here is my code
Code:
#include <stdlib.h>
#include <stdio.h>
#include <clib.h>
#include <DBOS\LIB.h>
void pic(int*,int,int);
int my_rand(int);
int find_max(int *a,int s);
int find_min(int *a,int s);
int main(void)
{
int range,num;
int a[300];
int k,s;
printf(" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
printf(" * Please pres r to run or press e to exit *\n");
printf(" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
k=getch();
/*run by pressing r and exit by pressing e*/
if (k=='r' || k=='R'){ /*accept both lower and upper case */
do{
printf("Enter the range size(max=20)");
scanf("%d",&range);
}
while (range<0 || range>20); /*move to next statment only if the input in range 1 to 20*/
printf("How many numbers do you wish to generate?");
scanf("%d",&num);
}
printf("Max count:%d\t",find_max(a,s));
printf("Minimum cont:%d\t",find_min(a,s));
printf("Expected: %d\n", (int) (num / range));
if (k=='e' || k=='E')
exit(1);
pic(a,range,num);
}
int my_rand(int range){
int r ;
date_time_seed();
r=1+rand()%range;
return r;
}
void pic(int *a,int range,int num){
int i,t;
t=0;
for(i=0; i<(num); i++){
a[i]=0;
for(i=0; i<num; i++)
{
t=my_rand(range);
a[t]=a[t]+1;
}
}
}
/* function to find the max*/
int find_max(int *a,int s){
int i,max;
max=0;
for(i=0;i<s;i++)
{
if(a[i]>max)
max=a[i];
}
return max;
}
/*function to find the min*/
int find_min(int *a,int s){
int i,min;
min=*a;
for(i=0;i<s;i++)
if(!(a[i]>min))
min=a[i];
return min;
}