-
Just my program...
/*
Author: Jacob Roman Date: 12/06/04
Class: COP 2220 Monday
Program #19 Chapter 12 Exercise 13
Description: Put's random values within an array and it searches it to check
if the value 32 is within it.
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define MAX_DAYS 7
#define MAX_HOURS 24
typedef int Bool;
Bool search(int[], int, int);
int main(void)
{
int Array_Size = 0;
int Temperatures[7][24] = {0};
int *i = 0;
Array_Size = sizeof(Temperatures)/sizeof(Temperatures[0]);
srand(time(NULL));
printf("Creating random values for the array...\n");
for (i = &Temperatures[0][0]; i <= &Temperatures[MAX_DAYS - 1][MAX_HOURS - 1];i++)
{
*i = (int)(rand() % 40);
//printf("%d\n",*i);
}
printf("Complete\n\n");
printf("Searching though the array for value 32...\n");
if (search(Temperatures[7],Array_Size,32) == TRUE)
{
printf("Search has found the value 32 within the array\n");
}
else
{
printf("Search has not found the value 32 within the array\n");
}
printf("Complete\n\n");
return 0;
}
Bool search(int a[], int n,int key)
{
int *i = 0;
for (i = &a[0];i <= &a[n]; i++)
{
if (*i == key)
return TRUE;
}
return FALSE;
}