Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(20 pts) Write a C++ program that creates a 2-dimensional array of 10x5 elements

ID: 3844530 • Letter: #

Question

(20 pts) Write a C++ program that creates a 2-dimensional array of 10x5 elements that are populated by random numbers between 0 and 49 (hint: use he rand() function and re-use code from the multi-dimensional array demonstration in class). The program should then ask the user for a number etween 0 and 49 and searches the array for that number. If it finds it, it returns both indicies of the 2-D array, otherwise, it returns a message that says did not find this number," Re-run your program multiple times to make sure that it works (it should show you different answers each time).

Explanation / Answer

random.c

#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{

int a[10][5], i , j;
int key=0,flag=1;;
for (i = 0; i < 10; i++)
{
for ( j = 0; j < 5; j++)
{
a[i][j] = GetRand(0, 49);
printf("%5d" , a[i][j]);
}
printf(" ");
}
printf("Enter The Number That Between 0 to 49: ");
scanf("%d",&key);
if(key<=49&&key>=0)
{
for (i = 0; i < 10; i++)
{
for ( j = 0; j < 5; j++)
{
if(a[i][j] ==key);
{
  
   flag=0;
   break;
       }
}
break;
printf(" ");
}  
}
else
{
   printf("search is Not Possible: ");
}
if(flag==0)
{
   printf("key is Found: ");  
}
else
{
   printf("key is not Exist ");
}
return 0;
}

int GetRand(int low, int high)
{
static int Init = 0;
int rc;
if (Init == 0)
{
srand(time(NULL));
Init = 1;
}
rc = (rand() % (high - low +1) +low);
return (rc);
}