Computer Science, asked by prathm2281, 9 months ago

Raju has a square-shaped puzzle made up of small square pieces containing numbers on them. He wants to rearrange the puzzle by changing the elements of a row into a column element and column element into a row element. Help Raju to solve this puzzle.

Answers

Answered by mayursanjaydeshmukh
7

Answer:

#include<iostream>

using namespace std;

int main()

{

   int r,c,i,j;

  int a[10][10];

  int b[10][10];

 cin>>r>>c;

 for(i=0;i<r;i++)

 {

   for(j=0;j<c;j++)

   {

     cin>>a[i][j];

   }

 }

 for(i=0;i<c;i++)

 {

   for(j=0;j<r;j++)

   {

     cout<<a[j][i]<<" ";

     

   }

   cout<<"\n";

 }

}  

Explanation:

All test Cases are passed.

Answered by poojan
0

Seems like you haven't typed the entire problem. Here is the answer with explanation.

Matrix Addition Program in Python, using the functions given in the data provided.

Language used : Python Programming

Program : (DYNAMIC, YOU CAN PROVIDE ANY NO.OF ROWS AND COLUMNS)

def createarray(a,b):

   x=int(input())       #no.of rows

  y=int(input())      #no.of columns

  getelement(x,y,a,b)

def getelement(x,y,a,b):

  for i in range(x*y):

      a.append(int(input()))

  for i in range(x*y):

      b.append(int(input()))

  addmatrix(x,y,a,b)

def addmatrix(x,y,a,b):

  for i in range(x):

      j=i*y

      for k in range(j,y+j):

          print(a[k]+b[k], end="  ")

      print()

a=[]

b=[]

createarray(a,b)

  

Input :

2

2

1

2

3

4

1

2

3

4

Output :

2     4

6     8

Explanation :

  • Take to empty lists and pass them through createarray() function.

  • Define a createarray() function, and ask the user to input row and column sizes.

  • Then, pass sizes and lists (which acts as arrays now as we are going to take in only integer values : so they act as arrays of type int) through function call of function getelement().

  • Create a function getelement() which takes in row*column size of elements into each arrays (2x2 matrix= 4 elements, 2x3 matrix = 6 elements).

  • Once done, pass the elements filled lists, sizes through the function call addmatrix() that adds the corresponding elements of the two lists and prints them in a matrix form. That's it.

Learn more :

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Indentation is must in python. Know more about it at :

brainly.in/question/17731168

3) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

4) Python program to find absolute difference between the odd and even numbers in the inputted number.

brainly.in/question/11611140

Attachments:
Similar questions