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...

  • *Answer must be in C* Write a program that: 1- Declare and initialize all values to...

    *Answer must be in C* Write a program that: 1- Declare and initialize all values to zero an array of doubles 10 x 10 named "cat" 2- Write the code(using for loops) to fill the array with values 1, 2, 3, .... 98, 99, 100 3- Output (using for loops) the sum of the diagonal from 1-100 4- Output (using for loops) the sum of the last 50 rows of the array

  • 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...

  • Purpose: The JAVA application will allow the student to; I. demonstrate the declaration of an array;...

    Purpose: The JAVA application will allow the student to; I. demonstrate the declaration of an array; II. demonstrate the initialization of the array; III demonstrate the printing of the elements of the array. Create a new file called "Array5A” . 1. Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of the application, the date of completion, and any additional notes.) 2. Write a Java statement to create...

  • 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

  • Please select the output: main         declare X as integer, Y as integer                        &nbsp

    Please select the output: main         declare X as integer, Y as integer                                 set x=1                                 set y=2                                 call sub(x, y)                                 write x                                 write y End program Subprogram sub( integer Num1 as ref, Integer Mum2 as reference)                                                              declare x as integer                                                 set Num1 = 3                                                 set Num2 = 4                                                 set x= 5                                                 write x end subprogram           Please select one:      5/42, 5/34, 5/32, 5/24 What is the output of this...

  • 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...

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