Question

In: Computer Science

You are offered with a partial specification of a 4x5 2-D array. The partial specification is...

  1. You are offered with a partial specification of a 4x5 2-D array. The partial specification is shown as follows. (Only the first row and the first column are specified.)

-1   -2   -3   -4   -5

-6

-11

-16

You are required to write a C program to perform two tasks.

  1. First, to write a sequence of C codes to generate the values for the unspecified elements in the 4x5 2-D array. The array is called A. The row index is denoted by i, and column index is denoted by j. i, j starts from 0. Namely, for first row, i = 0. For first column, j = 0. The values of the unspecified elements are defined as

A[i][j] = A[i-1][j]*A[i][j-1] for i > 0 and for j > 0.

After all elements in the 4x5 2-D array are fully specified, print out the content of the entire 4x5 2-D array according to the format shown below.

Solutions

Expert Solution

Well i have tried to explain each and everything in the code itself . But if you still dont get anything than ask in comment section please.

CODE :

#include <stdio.h>
#define row 4
#define col 5

int main() {

// as size of row and coloumns are predefined
// here long long is taken as multiplication can overflow
long long int A[row][col];

// putting te known values in A[][]
// initialsed first row first
for(int i=0;i<col;i++){
A[0][i]=-(i+1);   
}
// now first col is initialsed
for(int i=0;i<row;i++){
A[i][0]=-(5*i+1);   
}

// now the main part begins as we have already filled 1st row and 1 st col
// now we will traverse full 2d array starting from 1,1 to 3,4

for(int i=1;i<row;i++){
for(int j=1;j<col;j++){
A[i][j]=A[i-1][j]*A[i][j-1];   
}   
}

// finally printing arrary

for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
printf("%lld ",A[i][j]);
}
printf("\n");
}

return 0;
}

OUTPUT :


Related Solutions

Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n –...
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n – 1)] of n integers. Output: The largest index b such that A[b] is the largest value in A[0..(n – 1)]. For example, if n = 10 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 1, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 4, since the largest value in A is 8 and...
On the following code that contains a method which returns a new matrix (2-d array) with...
On the following code that contains a method which returns a new matrix (2-d array) with same number of rows and columns as has its parameter (matrix). Each entry in the returned array should equal the result of multiplying the entry at the same row and column in matrix by the value of scalar. code: package edu.buffalo.cse116; /** * Class which contains a method which takes in a 2-dimensional array and a scalar value and returns their product. */ public...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of the following methods with their appropriate parameters: a.) getData: This method reads and stores the data in the 2-D array. b.) averageHigh: This method calculates and returns the average high temperature of the year. c.)...
Using the partial ANOVA Table found in question d-2, please answer the following questions. Use the...
Using the partial ANOVA Table found in question d-2, please answer the following questions. Use the 0.05 significance level. How many treatments are there? What is the total sample size? What is the critical value of F? (Round your answer to 2 decimal places.) d-1. Write out the null and alternate hypothesis. d-2. From the information given above, fill in the blanks in the ANOVA table below. Calculate the value of F also. (Round the values to the nearest whole...
- Make a 2-D array to represent a Tic-Tac-Toe game/grid. Place a couple of 'X's and...
- Make a 2-D array to represent a Tic-Tac-Toe game/grid. Place a couple of 'X's and 'O's in the grid and display it. Do some extra printing to make it look like a Tic-Tac-Toe board we are suppose to use rows and columns so just make it simple thanks!
You are offered the following two bonds. Bond C Bond D Maturity 5 years 10 years...
You are offered the following two bonds. Bond C Bond D Maturity 5 years 10 years Bond rating AAA AAA Coupon 2% 3% YTM 2% 4% Par value 100 100 Assume the yield curve is flat. Suppose Bond C is correctly priced. Analyse Bond D to determine whether it is consistently priced in relation to Bond C.
JAVA!!!! int[][] BingoCardArray = new int[5][5]; Use a nested for-loop, to populate the 2-D array representing...
JAVA!!!! int[][] BingoCardArray = new int[5][5]; Use a nested for-loop, to populate the 2-D array representing 5 columns for B – I – N – G – O, where row 1 =         col 1 = random # 1- 15         col 2 = random # 16 – 30         col 3 = random # 31 – 45         col 4 = random # 46 – 60         col 5 = random # 61 – 75 row 2 =         col 1 = random # 1-...
If there are 3 quantum wells separated by the same distance in a 1-D array with...
If there are 3 quantum wells separated by the same distance in a 1-D array with wavefunction ψ1 , ψ2 , and ψ3 for these three quantum wells respectively. The electrons only acts on the neighboring electrons with perturbation energy H’ = -|ΔE|. If the original eigen energy of ψ1 , ψ2 , or ψ3 is E1, try to use degenerate perturbation theory to calculate and sketch the new eigen energies for this array with 3 quantum wells.
Question 2 You are offered a special set of annuities by your insurance company, whereby you...
Question 2 You are offered a special set of annuities by your insurance company, whereby you will receive $23,600 a year for the next 7 years, nothing for the next 10 years, and then $40,000 a year for the following 12 years. How much would you be willing to pay for these annuities today, if the annuities are paid at the beginning of each year? Assume the annuities have a beta of 1.47, the expected return on the market is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT