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 element in a column that he’ll specify. Print the
result.
4. Sum of the elements in the right diagonal. Print the
result.
5. Sum of the elements in the left diagonal. Print the
result.
6. The element with the minimum value in the array. Print the
result.
7. The element with the maximum value in the array. Print the
result.
8. The element with the minimum value in a row that he’ll specify.
Print the result.
9. The element with the maximum value in a row that he’ll specify.
Print the result.
10. The element with the minimum value in a column that he’ll
specify. Print the result.
11. The element with the maximum value in a column that he’ll
specify. Print the result.
12. Print the menu again
13. Exit from the program
d. The user can elect from the menu as any times as he wants
without leaving the program.
Code Explanation:
Code:
n =input("Enter n");
m =input("Enter m");
A =zeros(n,m);
for i=1:n
A(i,:)= randi([-100 100],1,m);
end
disp("The generated matrix with random integers is:\n");
disp(A);
choice = print_menu();
while(choice ~= 13)
if(choice == 1)
disp(sum(sum(A)));
elseif(choice == 2)
r = input("Enter row number");
disp(sum(A(r,:)));
elseif(choice ==3)
c = input("Enter column number :");
disp(sum(A(:,c)));
elseif(choice == 4)
disp(sum(diag(A)));
elseif(choice == 5)
disp(sum(diag(flip(A))));
elseif(choice == 6)
disp(min(min(A)));
elseif(choice == 7)
disp(max(max(A)));
elseif(choice == 8)
r = input("Enter a row number: ");
disp(min(A(r,:)));
elseif(choice == 9)
r = input("Enter a row number: ");
disp(max(A(r,:)));
elseif(choice == 10)
c = input("Enter a column number: ");
disp(min(A(:,c)));
elseif(choice == 11)
c = input("Enter a column number: ");
disp(max(A(:,c)));
elseif(choice == 12)
choice = print_menu();
elseif(choice ==13)
break
else
disp("Please enter a valid choice");
end
choice = input("select an option from menu");
end
function choice = print_menu()
disp("1.Sum of elements in the array\n");
disp("2.Sum of elements in a row\n");
disp("3.Sum of elements in a column\n");
disp("4.Sum of elements in right diagonal\n");
disp("5.Sum of elements in left diagonal\n");
disp("6.The element with minimum value in the array\n");
disp("7.The element with maximum value in the array\n");
disp("8.The element with minimum value in a row\n");
disp("9.The element with maximum value in a row\n");
disp("10.The element with minimum value in a column\n");
disp("11.The element with maximum value in a column\n");
disp("12.print the menu again\n");
disp("13.Exit from the program\n");
choice = input("Select an option from menu");
end
O/P:
Enter n
4
Enter m
5
The generated matrix with random integers is:\n
-30 66 17 10 84
-43 52 51 -24 14
-85 -90 6 56 87
-74 14 -6 -98 -33
1.Sum of elements in the array\n
2.Sum of elements in a row\n
3.Sum of elements in a column\n
4.Sum of elements in right diagonal\n
5.Sum of elements in left diagonal\n
6.The element with minimum value in the array\n
7.The element with maximum value in the array\n
8.The element with minimum value in a row\n
9.The element with maximum value in a row\n
10.The element with minimum value in a column\n
11.The element with maximum value in a column\n
12.print the menu again\n
13.Exit from the program\n
Select an option from menu
1
-26
select an option from menu
5
-103
select an option from menu
6
-98
select an option from menu
8
Enter a row number:
2
-43
select an option from menu
9
Enter a row number:
3
87
select an option from menu
12
1.Sum of elements in the array\n
2.Sum of elements in a row\n
3.Sum of elements in a column\n
4.Sum of elements in right diagonal\n
5.Sum of elements in left diagonal\n
6.The element with minimum value in the array\n
7.The element with maximum value in the array\n
8.The element with minimum value in a row\n
9.The element with maximum value in a row\n
10.The element with minimum value in a column\n
11.The element with maximum value in a column\n
12.print the menu again\n
13.Exit from the program\n
Select an option from menu
11
select an option from menu
13
>>
Code screenshot:
O/P screenshot:
(Please comment If you still have any doubts. I will definitely help)
Using Matlab Write a program which will: a. Accept two numbers from the user m and...
Using MATLAB 15. Write a program that: a. b. c. Accept two numbers n and m in the range of 1-6 Define three arrays A, B and Cof size n by m. (n-# of rows, m-H of columns) Fill the elements of array A by A(ij)-itj i-5 d. Fill the elements of array B by B(ij)ij e. Fill the elements of array C with the average of the corresponding elements of A f. g. h. and B Print the results...
2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()). Here is sample output Please enter number of elements: 4 Please enter the required numbers: 50 100 150 20 The entered numbers are: 50 100 150 20 Sum is : 320 Max is 150 by Mpsi ,sum and max to call subroutine and retrieve...
Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...
Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load them into an array. Add up all the values and store the answer in a variable. Find the largest and smallest number in the array. Put each into its own variable. Print to the screen the sum, largest value, and smallest value. Copy the array to a second array in reverse order. Print out the second array. Read in 20 integer numbers, all in...
Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...
Write a C Language Program that will ask the user how many elements the "maxminarray" will have. Read the elements from user and fill the "maxminarray” with it. Find maximum value and minimum value in maxminarray See the output below: Input number of elements of the array :6 Input 6 elements for the maxminarray : element [0]: 23 element [1] : 56 element [2] : 11 element [3]: 78 element [4]: 21 element [5]: 400 The Maximum element is :...
Write a program that will accept two numbers from the user. The program will then print all the numbers from the lowest number to the highest number. Make sure to include both numbers in the count. Also, it should not matter what order you input the two numbers. c++
Using Java In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...