Write a CC script that uses a Random Number generator nested

Write a C/C+ script that uses a Random Number generator nested inside a double for loop to create a 2 dimensioned matrix RN[N][M) of N x M random numbers between Min and Max (where N = # rows), M = # columns), Min and Max are all user inputs), then do a bin sort routine that places the random numbers into bins corresponding to binary divisible numbers (i.e. place all numbers evenly divisible by 2 into bin A, all numbers evenly divisible by 4 into bin B, all numbers evenly divisible by 8 into bin C, all numbers evenly divisible by 16 into bin D, all the way up to numbers evenly divisible by 64 into bin F.) Repeat this search for trinary numbers (i.e. Random ifs evenly divisible by 3, 9 or 27). Print these results in bins Tri1, Tri2 and Tri3. After writing your script, test with N= 200, M = 200, Min =0 and Max =7777 and print out your results. Print values for each bin .

Solution

// header files
#include<stdio.h>
#include<stdlib.h>

// main execution starts here
int main()
{
// required variables
int min,max,n,m;

// arrays with 20 as size to store the numbers
int binA[20],binB[20],binC[20],binD[20],binE[20],binF[20];

int Tri1[20],Tri2[20],Tri3[20];

// variables for operations index counts and loops
int i,j,k,l,binAI=0,binBI=0,binCI=0,binDI=0,binEI=0,binFI=0;
int Tri1I=0,Tri2I=0,Tri3I=0;

// prompting user for the values
Printf(\"Enter n and m values\ \");
scanf(\"%d%d\",&n,&m);

printf(\"Enter min and max values \ \");
scanf(\"%d%d\",&min,&max);
int array[n][m];

// double for loop for the given scenario n by m matrix
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
// statement generates a random number and stores it in the array
// within the specified max and min range
  
array[i][j]= rand()%(max+1-min)+min;

}
}

// Again double for loops to find the numbers
for(k=0;k<n;k++)
{
for(l=0;l<m;l++)
{
// Here checking if the number divisibility
  
// if divisible then loading into the respective array
// and incrementing the respective index
if(array[k][l]%2==0)
{
binA[binAI] =array[k][l];
binAI++;
}
else if(array[k][l]%4==0)
{
binB[binBI]=array[k][l];
binBI++;
}
else if(array[k][l]%8==0)
{
binC[binCI] =array[k][l];
binCI++;
}
else if(array[k][l]%16==0)
{
binD[binDI]=array[k][l];
binDI++;
}
else if(array[k][l]%32==0)
{
binE[binEI] =array[k][l];
binEI++;
}
else if(array[k][l]%64==0)
{
binF[binFI]=array[k][l];
binFI++;
}
else if(array[k][l]%3==0)
{
Tri1[Tri1I] =array[k][l];
Tri1I++;
}
else if(array[k][l]%9==0)
{
Tri2[Tri2I]=array[k][l];
Tri2I++;
}
else if(array[k][l]%27==0)
{
Tri3[Tri3I]=array[k][l];
Tri3I++;
}


}
}

// Printing writeen for 1 bin and Tri you can
// similarly write for remaining
for(int a=0;a<binAI;a++)
printf(\"%d \",binA[a]);

for(int t=0;t<Tri1I;t++)
printf(\"%d\",Tri1[t])


}

 Write a C/C+ script that uses a Random Number generator nested inside a double for loop to create a 2 dimensioned matrix RN[N][M) of N x M random numbers betwe
 Write a C/C+ script that uses a Random Number generator nested inside a double for loop to create a 2 dimensioned matrix RN[N][M) of N x M random numbers betwe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site