Question

In: Computer Science

Note: You can use only pointer based operations while implementing each of the functionalities below// zero...

Note: You can use only pointer based operations while implementing each of the functionalities below// zero points will be given if pointer operations are not used in implementing // each of the operations below. // Also, use C code only in visual studio or GCC

i) Create a 2 - D array of integers using pointers (use dynamic memory allocation) in C. Assume that the array has 4 rows and 5 columns.Then, fill the array with randomly generated int values between 1 and 100. */

ii.) Find the largest values in the array

iii.) Find the smallest value in the 1st row

iv.) Find the smallest value in the 1st column

v.) Display the elements in the diagonal

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

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

int main(){
  
   srand(time(NULL));
   int ROWS = 4;
   int COLUMNS = 5;
   int**p = (int**)malloc(sizeof(int*)*ROWS)   ;
   int row,col;
   // // fill 2d array will random numbers
   for(row=0; row<ROWS; row++){
       *(p+row) = (int*)malloc(sizeof(int)*COLUMNS);
       for(col=0;col<COLUMNS;col++){
           *(*(p+row)+col) = rand()%100 +1;
           printf("%4d",*(*(p+row)+col));
       }printf("\n");
   }
   //ii.) Find the largest values in the array
   int largest = **p;
   for(row=0; row<ROWS; row++){
       for(col=0;col<COLUMNS;col++){
           if(*(*(p+row)+col)>largest) largest = *(*(p+row)+col);
       }
   }
   printf("Largest Number in the 2-D array: %d\n", largest);
  
   //iii.) Find the smallest value in the 1st row
   int smallest = **p;
   for(col=0; col<COLUMNS;col++){
       if(*((*p)+col)<smallest) smallest = *((*p)+col);
   }
  
   printf("Smallest Number in the first row: %d\n", smallest);
  
   //iv.) Find the smallest value in the 1st column
   smallest = **p;
   for(row=0; row<ROWS;row++){
       if(*(*(p+row))<smallest) smallest = *(*(p+row));
   }
   printf("Smallest Number in the first column: %d\n", smallest);
  
   //v.) Display the elements in the diagonal
   printf("Diagonal Numbers:");
   for(row=0; row<ROWS; row++){
       for(col=0;col<COLUMNS;col++){
           if(row==col) printf("%d ",*(*(p+row)+col));
       }
   }

   return 0;
}
=====================================================================


Related Solutions

#include<stdio.h> #include<stdlib.h> int main() {     //Q1) Note: You can use only pointer based operations while...
#include<stdio.h> #include<stdlib.h> int main() {     //Q1) Note: You can use only pointer based operations while implementing each of the functionalities below    // zero points will be given if pointer operations are not used in implementing    // each of the operations below.    // Also, use C code only in visual studio or GCC in general.asu.edu server    /* i.) Create a 2 - D array of integers using pointers (use dynamic memory allocation).            Assume that...
Can you write a small program in c++ demonstrate the use of pointer (*) & (&)....
Can you write a small program in c++ demonstrate the use of pointer (*) & (&). Can you also explain the pointer system and how to use them. Thank you.
explain what a while loop is and how you can use it. Give examples based on...
explain what a while loop is and how you can use it. Give examples based on websites on how you can use a while loop to your advantage. This assignment should be a couple paragraphs long (5-8 sentences per paragraph).
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS....
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS.                          3)Use of string and char is not allowed.             Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256.
Which technique would you use to determine the following? You can only use each technique once....
Which technique would you use to determine the following? You can only use each technique once. Not all techniques will be used. Explain your answer. techniques available: - SDS-PAGE and Western blot - TLC - freeze-fracture - lactoperoxidase labeling - FRAP/photobleaching - photoactivation - hydropathy plot 1. You want to determine if a membrane has proteins in it or not. 2. You want to determine if a cell membrane has the Na+/K+ transporter. 3. You want to determine the types...
Imagine France and the US are exclusive trading partners. French people can only use Euros while...
Imagine France and the US are exclusive trading partners. French people can only use Euros while Americans can only use dollars. What happens to the exchange rate of either euros or dollars with the following changes? Explain carefully in a paragraph or two: US exporting industries become more productive. The French government doubles the money supply. The US government decides to increase their tariffs on delicious French Cheeses
For the following questions, you can use any structure you have learned until now (While/Do-While/ for...
For the following questions, you can use any structure you have learned until now (While/Do-While/ for loops, if-statement, switch-case statement). Question2: Find all prime numbers between 10 to 100. hint: a prime number is a number that is divisible by 1 and itself. for example 3, 5, 7, 11, 13 are prime numbers because they are only divisible by 1 and themselves.
Choose the degree AND the type of elasticity list for each event below: Please use ONLY...
Choose the degree AND the type of elasticity list for each event below: Please use ONLY lower case letters as your answers. Degree Type a) perfectly elastic f) price elasticity of demand b) elastic g) price elasticity of supply c) unit elastic h) cross elasticity (substitute) d) inelastic i) cross elasticity (complement) e) perfectly inelastic j) income elasticity (normal) k) income elasticity (inferior) Part 1. Egg prices change by -6 % causing the demand for toast to change by 3...
(In C) Note: Can you create an example code of these tasks. use any variables you...
(In C) Note: Can you create an example code of these tasks. use any variables you wish to use. postfix expressions: (each individual text (T), (F), (NOT), etc is a token) F T NOT T F NOT T T T AND F T F NAND (1) Create stack s. (2) For each token, x, in the postfix expression: If x is T or F push it into the stack s. (T = true, F = false) Else if x is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT