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

Write th following program in C: 1. Create an array of 100 random numbers in the

ID: 3690587 • Letter: W

Question

Write th following program in C:

1. Create an array of 100 random numbers in the range of 1…999, write a function for each of the following processes. In building the array, if 3 or 7 evenly divide the random number, store it as a negative number.

a.       Print the array ten values to a line. Make sure that the values are aligned in rows.

b.      Return a count of the number of even values

c.       Return the sum of all values in the array       

2. Create a two dimensional array (size 10 X 10). Fill this two dimensional array with the values from the above single dimensional array. Determine the maximum value in each row.  Display the two-dimensional array and the maximum of each row.

3. Repeat number 2 above but this time instead of 10 X 10 array, prompt the user for the size of the row and column, allow user to fill in the values and display the array.(Hint: Use pointers and dynamic memory allocation )

Explanation / Answer

// code start here

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void printarray(int rndarray[]);
void oddarray(int rndarray[]);
int countevenary(int rndarray[]);
int sumary(int rndarray[]);


int main()
{
int rndarray[100]; // array
int x,y; // index
int current;
srand(time(NULL)); // initialize random sequencer

for (x = 0; x < 100; x++)
{
current = rand()%1000 + 1;
//printf("%d ", current);
rndarray[x] = current;
}
// call print array function here
printarray(rndarray);
// call evenarray function here this function return count of even value in array
int even = evenarray(rndarray);
// call sum of array value here. this function return sum of all value in array
int sum = sumarray(rndarray);
printf("Count of the number of even values :- ");
// show count of even value here
printf("%d ",even);
printf("Sum of all values in the array :-");
// show sum of all value in array
printf("%d ",sum);
// call array2d function. this function add value in 2d arry from single array and print array
array2d(rndarray);
// call custim2d array function here.
custom2d();
  
system("pause");
return 0;
}
/* this function use for get user input and set size of 2d arrya.
* after size of array get user input for array value then print array value
* */
void custom2d(){
int a,b,c,x,y;
printf("Please enter the size of the row for2d array row:-");
scanf("%d", &a);
printf("Please enter the size of the row for2d array column:-");
scanf("%d", &b);
int array2D[a][b];
for (x = 0; x<a ; x++){
for (y = 0; y<b ; y++){
printf("Please enter the value :-");
scanf("%d", &c);
array2D[x][y] = c;
}
}
for (x = 0; x<a ; x++){
for (y = 0; y<b; y++){
printf("%3d ", array2D[x][y]); // prints 10 numbers to a line
}
printf(" ");
}
  
}
// this function use for fill 2d array value from single array and print value
void array2d(int rndarray[]){
int array2D[10][10];
int x,y,c=0;
for (x = 0; x<10 ; x++){
for (y = 0; y<10 ; y++){
array2D[x][y] = rndarray[c];
c++;
}
}
printf("The 2d array values to a line ");
for (x = 0; x<10 ; x++){
for (y = 0; y<10; y++){
printf("%3d ", array2D[x][y]); // prints 10 numbers to a line
//printf("%d", array2D[x][y]);
}
printf(" ");
}
}
// this function use for get sum of all value in array
int sumarray(int rndarray[])
{
int x;
int count;
for (x = 0; x < 100; x++)
{
count= rndarray[x];
  
}
return count;
}
// this function use for print single array
void printarray(int rndarray[])
{
int x;
int numPrinted = 0;
for (x = 0; x < 100; x++)
{
if ((rndarray[x] % 3 == 0) || (rndarray[x] % 7 == 0))   
rndarray[x] = 0 - rndarray[x];
}

printf("The array ten values to a line ");

for (x = 0; x < 100; x++)
{
printf("%3d ", rndarray[x]); // prints 10 numbers to a line
if (numPrinted < 9)
numPrinted++;
else
{
printf(" ");
numPrinted = 0;
}
}
}
// this function use for count even value in the current array
int evenarray(int rndarray[])
{
int x;
int count = 0;

for (x = 0; x < 100; x++)
{
if (rndarray[x] % 2 == 0)
count++;
  
}
return count;
}

// code end here

Output of 3 point:-

Please enter the size of the row for2d array row:- 2

Please enter the size of the row for2d array column:- 3

Please enter the value :- 23

Please enter the value :-45

Please enter the value :-87

Please enter the value :-98

Please enter the value :-78

Please enter the value :-89

23 45 87

98 78 89

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote