design an algorithm(pseudocode or C) from the content of a table, we want to generate an array of the same number of rows and columns as the measure of the vector. In the first row of the new matrix we will copy the vector and in the following we will do the same.
Since some of the positions have to be at 0, it is best to initialize the entire array to 0 first.
Table indices ** are always integer values **.
example
|Vector||||
|:--:|:--:|:--:|:--:|
| 4 | 3 | 2 | 1 |
|Matrix||||
|:--:|:--:|:--:|:--:|
| 4 | 3 | 2 | 1 |
| 0 | 3 | 2 | 1 |
| 0 | 0 | 2 | 1 |
| 0 | 0 | 0 | 1 |
Output:

CODE:
#include<stdio.h>
int main()
{
int n;
//get the number of items from the user
printf("Enter the number of elements in the vector\n");
scanf("%d",&n);
printf("Enter %d items\n",n);
int vector[n];
//input n elements of the vector
for(int i=0;i<n;i++)
{
scanf("%d",&vector[i]);
}
//create a n*n matrix
int matrix[n][n];
//initialize the matrix to 1
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
matrix[i][j]=0;
}
}
//desired values in the matrix
for(int i=0;i<n;i++)
{
//start j loop from j=i to n
for(int j=i;j<n;j++)
{
matrix[i][j]=vector[j];
}
}
//print the matrix
printf("Matrix is\n");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
printf("%d ",matrix[i][j]);
}
printf("\n");
}
return 0;
}
design an algorithm(pseudocode or C) from the content of a table, we want to generate an...
Diagonal Difference HackerRank Pseudocode and C++: Given a square matrix, calculate the absolute difference between the sums of its diagonals. Function Description Complete the diagonalDifference function described below to calculate the absolute difference between diagonal sums. diagonalDifference( integer: a_size_rows, integer: a_size_cols, integer array: arr) Parameters: a_size_rows: number of rows in array a_size_cols: number of columns in array a: array of integers to process Returns: integer value that was calculated Constraints -100 < = elements of the matrix < = 100...
Goal Design and implement an algorithm to input the data representation of two graphs, determine if the graphs are complements of each other and, if so, outputs a message that the graphs are complements then outputs the degrees of the vertices of each graph, otherwise outputs a message to the contrary and immediately terminates. Details Input to your program consists of the representation of two graphs and will be in the following format: an integer m representing the number of...
Java
Here is the template
public class ShiftNumbers {
public static void main(String[] args) {
// TODO: Declare matrix shell size
// TODO: Create first row
// TODO: Generate remaining rows
// TODO: Display matrix
}
/**
* firstRow
*
* This will generate the first row of the matrix, given the size n. The
* elements of this row will be the values from 1 to n
*
* @param size int Desired size of the array
* @return...
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...
Write a C++ program that creates a ragged table (i.e. a table with rows of different length) using a vector of vector of integers. Your program should prompt the user for a file name, open the file, read the content of the file and store it in a vector or vectors, and finally print the content of the vector of vectors. Sample Input: Enter the file name: data.dat A sample file might contain: 6 5 2 4 5 3 2...
Your array shall have 3 rows and 3 columns (row and column indices are from 0 to 2). You shall initialize all elements of your array with character 'v' Player-1 is assigned 'X' symbol and player-2 is assigned 'O' symbol. Player-1 shall start the game and enter row index and column index where (s)he wants to place an 'X'. The board is updated and displayed. Now player-2 is asked to enter row and column indices If any player tries to...
In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain...
def stochastic_gradient_descent(feature_matrix, label,
learning_rate = 0.05, epoch = 1000):
"""
Implement gradient descent algorithm for regression.
Args:
feature_matrix - A numpy matrix describing the given data, with
ones added as the first column. Each row
represents a single data point.
label - The correct value of response variable, corresponding to
feature_matrix.
learning_rate - the learning rate with default value 0.5
epoch - the number of iterations with default value 1000
Returns: A numpy array for the...
Please answer this in python
pseudocode. It's an algorithm question.
1. [10 marks] Consider the function SumKSmallest(A[0..n – 1), k) that returns the sum of the k smallest elements in an unsorted integer array A of size n. For example, given the array A=[6,-6,3,2,1,2,0,4,3,5] and k=3, the function should return -5. a. [3 marks) Write an algorithm in pseudocode for SumKSmallest using the brute force paradigm. Indicate and justify (within a few sentences) the time complexity of your algorithm. b....
(Written in C++) Your assignment is to generate an HTML multiplication table with dimensions specified by the user. You will ask the user for the number of rows then number of columns, and generate an HTML table of the appropriate size. The top left cell should contain the result of 1 x 1, and the bottom right cell should contain the result of num_rows x num_cols. Each row and column may be an integer value between 1 and 12 inclusive...