Question

Use C:

3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of zeros. Parameters are the array, number of rows, number of columns, and pointers to the number of positives, number of negatives, and number of zeros Call a function printResults to print the array and the number of positives, negatives, and zeros. There are six parameters, including the number of rows and columns, none of which needs to be a pointer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

#include <stdio.h>

#include <stdlib.h>

#include<string.h>

#include <stdlib.h>

#include <time.h>

//function declarations

void createArray(int rows,int cols,int arr[rows][cols]);

void signs(int rows,int cols,int arr[rows][cols],int *cntPos,int *cntNeg,int *cntZeros);

void printresults(int rows,int cols,int arr[rows][cols],int cntPos,int cntNeg,int cntZeros);

int main()

{

//Declaring variables

const int rows=5,cols=4;

int cntPos=0,cntNeg=0,cntZeros=0;

int arr[rows][cols];

  

//calling the functions

createArray(rows,cols,arr);

signs(rows,cols,arr,&cntPos,&cntNeg,&cntZeros);

printresults(rows,cols,arr,cntPos,cntNeg,cntZeros);

return 0;

}

void createArray(int rows,int cols,int arr[rows][cols])

{

srand ((unsigned)time(0));

int i,j;

for(i=0;i<rows;i++)

{

for(j=0;j<cols;j++)

{

arr[i][j]=rand()%(41)-20;

}

}

}

//This function count no of positives negatives and zeros

void signs(int rows,int cols,int arr[rows][cols],int *cntPos,int *cntNeg,int *cntZeros)

{

int i,j,cntp=0,cntn=0,cntzero=0;

for(i=0;i<rows;i++)

{

for(j=0;j<cols;j++)

{

if(arr[i][j]<0)

cntp++;

else if(arr[i][j]>0)

cntn++;

else

cntzero++;

}

}

*cntNeg=cntn;

*cntPos=cntp;

*cntZeros=cntzero;

}

//This function will print the results

void printresults(int rows,int cols,int arr[rows][cols],int cntPos,int cntNeg,int cntZeros)

{

int i,j;

printf("Displaying the array\n");

for(i=0;i<rows;i++)

{

for(j=0;j<cols;j++)

{

printf("%d\t",arr[i][j]);

}

printf("\n");

}

printf("\nNo of Positives :%d\n",cntPos);

printf("No of Negatives :%d\n",cntNeg);

printf("No of Zeros :%d\n",cntZeros);

}

__________________________

Output::

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\TwoDimensionalArrayRandomNosBetween-20To20. Displaying the array 12 12 -10 -7 -6 -14 15 12 2 4 -7 -19 No of Positives 9 No of Negatives 11 No of Zeros :0 9.83226 seconds with ret Process exited after Press any key to continue - - . urn value 0

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hand-write code to declare a two dimensional array of 3 columns and 4 rows. The Array...

    Hand-write code to declare a two dimensional array of 3 columns and 4 rows. The Array will hold doubles. What is the array initialized to by default?

  • ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....

    ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size. For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row. For Grade 9) Calculate the sum of positive values for each column. To obtain inputs and return the results, define appropriate type C/C++ functions. Please...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of...

    Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of integers, declared to be "int** A," to the standard output. Each of the rows should appear on a separate line. Your input will be as follows with the first two values being the number of rows and columns respectively. HINT: This is best done with one for-loop nested within another Sample 1/0 1: Input: 3 2 1 2 3 4 Ол 6 Output: 12...

  • Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of...

    Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function  f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and...

    Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional array. Within C program (the MAIN function); Declare a two- dimensional 3X2 integer array A and initialise with the values (1,2), (3,4), (5,6), declare also a two-dimensional 2X3 integer array B and initialise it with zero. Call the FUNCTION and pass arrays A and B to the FUNCTION as arguments. Print the array A and its transpose....

  • Complere a c++ function that returns the sum of all elements in a two-dimensional array of...

    Complere a c++ function that returns the sum of all elements in a two-dimensional array of double's: const int COLUMNS = 5; double sum(double values[][COLUMNS], int rows) {

  • How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using...

    How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using namespace std; int main() {    // Q#5 - dynamic 2d arrays, indexing via subscript operator, pointer arithmetic    // tic tac toe board is an array of int pointers    // each int pointer in the board points to a row    // declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int)    const...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT