Here I am providing the answer for the above question:
Code:
#include <stdio.h>
#include<stdlib.h>
#define M 4
#define N 3
void printArray2D(int A2D[][N])
{
for(int i=0;i<M;i++)
{
for(int j=0;j<N;j++)
printf("%d ",A2D[i][j]);
printf("\n");
}
}
void populateRandom2D(int A2D[][N])
{
int max,min;
printf("Enter min number in the array:");
scanf("%d",&min);
printf("Enter max number in the array:");
scanf("%d",&max);
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
A2D[i][j] = (rand() % (max - min + 1)) + min;
printf("Array is filled.\nThe array is:\n");
printArray2D(A2D);
}
void linearSearch2D(int A2D[][N])
{
int key,flag=0;
printf("Enter the value to be searched:");
scanf("%d",&key);
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
if(A2D[i][j]==key)
{
printf("Value found\n");
flag=1;
break;
}
if(flag==0)
printf("Value not found");
}
void rightShift2D(int A2D[][N])
{
printf("Before Rotate:\n");
printArray2D(A2D);
int left,right;
for(int i=0;i<M;i++)
{
right=A2D[i][N-1];
A2D[i][N-1]=A2D[i][N-2];
A2D[i][N-2]=A2D[i][0];
A2D[i][0]=right;
}
printf("After Rotate:\n");
printArray2D(A2D);
}
int main()
{
int A2D[M][N],option,flag=0;
while(1)
{
printf("\nLab3\n--------\n1 - Fill the array\n2 - Search the
array\n3 - Right shift the array\n0 - Quit\n\nPlease enter a
selection:");
scanf("%d",&option);
switch(option)
{
case 1:
populateRandom2D(A2D);
break;
case 2:
linearSearch2D(A2D);
break;
case 3:
rightShift2D(A2D);
break;
case 0:
flag=1;
printf("Thanks for using!!!");
break;
}
if(flag==1)
break;
}
}
Screenshot of the program:
Output:
Hoping that the above answer will help you...Thank you...
COMP1410 - Lab Exercises #3 (Due at the end of the lab period or beginning of...
X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals ;;;;; Q1: Don't forget to document your program ; Name:Yuyan Wang ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places in the file. ;;;;; Hint: the appropriate place is not always right below the question. ;;;;; Q2: Write the directive to bring in the IO library ;;;;; Q3: Create a constant called MAX and initialize it to 150...
c++. please show screenshots of output This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_funch and store all the functions in project11_func.cpp. Make sure you have proper header comments in each.h,.cpp file. When you run your program, your sample output should show your name. Your report should include the following: 1) project11_func.h 2) project11_func.cpp 3) project11.cpp 4) sample output Write the following functions: a) void fill_array_with_random_nums(int array(), int N): Fill array...
Using c++ 1 of 2 Assignment 5 Lab Section 3 write a program create a vector with random numbers. Use merge sort to reorder the vector Prompt user to enter a number to search in the vector. If there are more than one number in the vector equal to the search value, display the indices remove the repeated numbers. If found just one matching number, display the index. If no matching number, prompt user for 2 options: add to the...
//please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks import java.util.*; public class Test { /** Main method */ public static void main(String[] args) { double[][] matrix = getMatrix(); // Display the sum of each column for (int col = 0; col < matrix[0].length; col++) { System.out.println( "Sum " + col + " is " + sumColumn(matrix, col)); } } /** getMatrix initializes an...
Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...
Using Matlab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Provide the user the following menu from which he can select: 1. Sum of all elements in the array. Print the result. 2. Sum of the element in a row that he’ll specify. Print the result. 3. Sum of the...
Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...
Write a C++ program that calculates the working hours of multiple employees during a weekday. The program will take the last digits of your student id as the number of row employees of the array (if your last digits are less than or equal to 7 add 3 to it) and the weekdays are the column then fill the array with using random integer inputs (between 0 - 10 ) (stores the random numbers in a 2D array using both...
Please write a JAVA program according to following requirement. Thanks Part 2 -Arrays We can use the Math.random method to generate random integers. For example, Math.random () generates a random integer greater than or equal to 0 and less than 1. The expression Math. random) 6generates random numbers between 0 and 5, simulating the throw of a die. In this lab assignment, you will use an array to test whether the random generator is fair; that is, whether each possible...
using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...