Write a C program that uses mallloc to create a 2D array. of c columns and r rows.
Elements of array must be initialized to 0 and you must use malloc and free allocated memory fo array.
ANSWER:-
#include <stdio.h>
int main(void) {
int r, c;
printf("enter the row : ");
scanf("%d",&r);
printf("enter the column : ");
scanf("%d",&c);
int *arr = (int *)malloc(r * c * sizeof(int));
int i, j, count = 0;
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
*(arr + i*c + j) =count;
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
printf("%d ", *(arr + i*c + j));
}
printf("\n");
}
free(arr);
return 0;
}
// OUTPUT

// please vote
Write a C program that uses mallloc to create a 2D array. of c columns and...
C PROGRAM the functions create and free a dynamically allocated 2D array. It should function like a statically allocated array (use malloc()) int **createArray(int rows, int cols) parameters to this function are the number of rows and cols in the array. The return value is the array that you have dynamically allocated void freeArray (int **array, int rows, int cols) the parameters to this function are: -the array created by createArray() -the number of rows in the array -the number...
C PROGRAM the functions create and free a dynamically allocated 2D array. It should function like a statically allocated array (use malloc()) int **createArray(int rows, int cols) parameters to this function are the number of rows and cols in the array. The return value is the array that you have dynamically allocated void freeArray (int **array, int rows, int cols) the parameters to this function are: -the array created by createArray() -the number of rows in the array -the number...
Write a Java program that does the following. a. Declare an integer 2D array with 5 rows and 5 columns. b. Initialize the array's elements to random integers between 1 and 10 (inclusive). c. Display all the elements in the 2D array as a table of rows and columns. d. Display the row index and column index of all the even integers in the 2D array. e. Display the sum of first row's elements.
Create a program that uses a Jagged Array. The program will create an array with 50 rows. Each of the values for each element of the array will be randomly generated. The random values will be between 1 and 20. Depending on the value generated for each row, you will create an array with that number of columns for that row. Each column created will contain the value to the left plus 1. After you create and populate the entire...
In C++ for 2D Array:
Write a program that uses a function that manipulates a 2D array of integers as follows: 1. Fill the first row and column in the array with random bits 2. Every subsequent cell should be filled as follows: 1. If the cells that are to the left and top of it are equal, then you should store their sum in it b. Otherwise, your program should store the highest among them. Test your function using...
Iterating over a 2D array If we want to visit or process every element of a 2D array, we need a nested for loop to do it. Generally, when you iterate over a 2D array, you want to do it in row major order, because this is more memory efficient. The reason why is that adjacent elements in a row are stored contiguously (one after another) in memory. Another reason, for an English speaker, is that this is the same...
Write a function called arrFactory that takes the address of an int** and two int values, rows and cols. The function will use dynamic memory allocation such that after the function call the int** can be used as a 2D array with the specified number of rows and columns. All elements of the array must be set to 0 within the function without iterating through each element after the array is created. The function has a return type of void....
Write a program in C++ that uses a class template to create a
set of items.
. . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...
Write a C# program(s) using arrays Create a 2D array of integers [8,4] Create a 3D array of integers [4,4,2]
create a program with files, 1d array, 2d array, and vectors in c++ a single program