Question

Declare a 4 x 5 array called N. Write a subprogram called printlt to print the...

Declare a 4 x 5 array called N.

Write a subprogram called printlt to print the values in N. Use this subprogram to print the values in the array after each part of the initialization exercise.

Write the loops to initialize the array to the following:

A.

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

B.

1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4

and print those out using your subprogram.

Please put the code in python and able to be copy paste, Thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Probably the code i designed will help for your problem:-

(indentations are needed in the code)

wherever i understood you asked to initialize array using loops and then implement a function to print that array

i declared the function "printlt()" as you stated it in the question , it will take array as a parameter and the inner loops will print elements of the array in the given order.

your code to implement starts here:-

code:-

def printlt(n):
   for i in range(4):
       print()
       for j in range(5):
           print(n[i][j],end="")
   print()
#initializing matrix A
x=[]
n=[]
for i in range(1,6):
   x.append(i)
for i in range(0,5):
   n.append(x)
printlt(n)
del(x)
del(n)
n=[]
for i in range(1,5):
   x=[]
   for j in range(5):
       x.append(i)
   n.append(x)
   del(x)
printlt(n)

end of code

thanku.

Add a comment
Know the answer?
Add Answer to:
Declare a 4 x 5 array called N. Write a subprogram called printlt to print the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5) Write TOY AL subprogram that implements the following subprogram interface: Label: SumEven On entry: Register $1...

    5) Write TOY AL subprogram that implements the following subprogram interface: Label: SumEven On entry: Register $1 is the return address of the caller. Register $A is the address in memory of an array A. Register $s is the size of the array A. On exit: Register $F is the sum of the entries of A that are even (divisible by 2) No values in memory have changed. Any of the registers may have changed value. Hint: The TOY assembly...

  • C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists...

    C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...

  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...

  • In C language 1. Write a program to declare and initialize an array of size 5...

    In C language 1. Write a program to declare and initialize an array of size 5 and place odd numbers 3, 5, 7,9 and 11 in it. Declare and initialize another array of size 5 and place even numbers 4, 6, 8, 10 and 12 in it. Write a for loop to add each element and place it in a third array of the same dimensions. Display each array.

  • *C CODE* 1. Declare an array of doubles of size 75 called scoreBonus and initialize all...

    *C CODE* 1. Declare an array of doubles of size 75 called scoreBonus and initialize all the elements in the array to 10.5 2. Declare an array of integers called studentNumbers The array can hold 112 integers Prompt and get a number from the user for the third element in the array Prompt and get a number from the user for the last element in the array

  • Write a program demonstrating your understanding of arrays: Declare, initialize and printout the contents of the...

    Write a program demonstrating your understanding of arrays: Declare, initialize and printout the contents of the following: 1. an integer array with 100 random values in it (select your random numbers from this domain: [1,1000])        To instantiate a random number object put the following line in the Main() method at the beginning of the function:                Random rndm = new Random();   // thanks Nicolas and Alexander!!         To ask for a random number from the random number object put...

  • 1.The code box below includes a live 2 dimensional array variable called gridNums. This array holds...

    1.The code box below includes a live 2 dimensional array variable called gridNums. This array holds integers. You cannot see its declaration or initialization. What value is in the zeroth (initial) position of the second row? Print this array entry to the console. (Note: remember that the second row is actually row 1). Enter your code in the box below. 2.The code box below includes a live 3x3 2-dimensional array variable called fredsNums. This array holds integers. You cannot see...

  • C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point...

    C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...

  • Which of the following statements is true about this array declaration? Declare Integer numbers [5] =...

    Which of the following statements is true about this array declaration? Declare Integer numbers [5] = 123,456,789,321, 654 This is an error: there should be 6 integers in the array. This is an array declaration and initialization. This is an error; the values of the array should be 1, 2, 3, 4,5 0 None of these statements are true.

  • Write common assembly language (RISC) programs to a) sum the first n elements of an array...

    Write common assembly language (RISC) programs to a) sum the first n elements of an array A, and b) compute r = ab for unsigned integers a and b. Each program will consist of a driver and a subprogram. The drivers will 1) read one or more values from the keyboard, 2) call the subprogram, and 3) print a result. The subprograms must not: ● store into memory, ● use registers $1 – $9, or ● make system calls

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT