hi guys can you help me to my project i got lot to do so i dont know wer to start..one of my project is to write a menu driven program that allows the user to fill anarray of 50 integers with random numbers in the range of 1-999,sort it,and then search it to determine if a given random number was generated.the menu is shown below:
MENU
[F] Fill array with random numbers
[P] Print the array
[S] sort the array (selection Sort)
[Q] Quuery the array (Binary Search)
[T] terminate the program
@ each time the fill option is executed, it will fill the array wth a new number series.
@use any of the sort algorithms
@if the query locates the number ,it will print the messege that the num was locte and the ndx loction wer it was fund
@if d query does not locte d num it will prnt d numb was not on the list and then print d value and ndx location of d largest num less than d target and d smallest value graeter than d requestet number.
Are you OP also? Anyway, you know how to loop through an array I assume. There is a rand() function that produces random numbers. It's in the <cstdlib> header.
Remember, you'll have to seed the rand() function using srand(). This is different than other languages that don't need any seeding to generate different numbers.
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# define MAX 50
# define TRUE 0
# define FALSE 1
int main(void)
{
int a[50]={MAX};
int array [50]={MAX};
int x;
int Print;
int Sort;
int Query;
int Terminate;
int left = 0;
int right = 50;
int middle = 0;
int number = 0;
int bsearch = FALSE;
int i = 0;
for(x=0; x<50; x++)
if (array[5] == Print)
printf("P\n");
else
if (array[50] == Sort)
printf("S\n");
srand(time(NULL));
for (i=1;i<=MAX;i++)
printf("%d\t",1+(rand()%999));
if(number == array[middle]) {
bsearch = TRUE;
printf("** Number Found **\n");
} else {
if(number < array[middle]) right = middle - 1;
if(number > array[middle]) left = middle + 1;
}
}
if(bsearch == FALSE)
printf("-- Number was not in the list --\n");
printf("MENU\n\n");
printf("F.Fill\nP.Print\nS.Sort\nQ.Query\nZ.Terminate\n");
printf("Please enter the option you selected: ");
scanf("%d\n", &Print,&Sort,&Query,&Terminate);
printf("The option you selected is %d\n ");
printf("The random number is %d\n",x);
return 0;
}