{"results": {"id": 705140, "problem_name": "Addition of two square matrices", "problem_type": 1, "problem_type_text": "Function", "publish": 1, "publish_date": "2020-10-21 15:49:16", "slug": "addition-of-two-square-matrices4916", "problem_level": -1, "problem_level_text": "Basic", "difficulty": "Basic", "marks": 1, "is_sample_input_modified": 1, "custom_input_format": "<p>Custom input should contain 2*n + 1 lines. First line should contain n. Each of next 2*n line contains n elements.<br /><strong>Example:</strong></p>\n<pre>2\n1 2\n3 4\n4 3\n2 1\n</pre>", "multiple_testcase": 1, "content_type": 1, "visibility_type": 1, "visibility_text": "public", "is_contest_problem": 0, "contest_slug": null, "can_add_interview_link": false, "can_edit_all_submissions_link": true, "has_all_submissions_button": false, "all_submissions": 20516, "accuracy": "61.66%", "is_user_login": 0, "is_private_tag_visible": false, "problem_category": 0, "related_courses": {}, "tags": {"company_tags": [], "topic_tags": ["Matrix", "Data Structures"]}, "problem_question": "<p><span style=\"font-size: 14pt;\">You are given two square matrices, a[][] and b[][], each of size n x n. Your task is to compute the sum of these two matrices and store the result in the matrix a[][] itself.</span></p>\n<p><span style=\"font-size: 18px;\"><strong>Examples:</strong></span></p>\n<pre><span style=\"font-size: 18px;\"><strong>Input: </strong>a[][] = [[1, 2], [3, 4]],\n       b[][] = [[4, 3], [2, 1]]\n<strong>Output: </strong>[[5, 5], [5, 5]]<br /><strong>Explanation:</strong> The will be: [[5, 5], [5, 5]] on adding the corresponding elements of both matrices.</span>\n</pre>\n<pre><span style=\"font-size: 18px;\"><strong>Input: </strong>a[][] = [[7, 8], [9, 10]],\n       b[][] = [[1, 2], [3, 4]]\n<strong>Output: </strong></span><span style=\"font-size: 18px;\">[[8, 10], [12, 14]]<br /><strong>Explanation:</strong> The result will be </span><span style=\"font-size: 14pt;\">[[8, 10], [12, 14]] after adding the corresponding elements of both matrices</span><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\">.</span>&nbsp;</pre>\n<p><span style=\"font-size: 18px;\"><strong>Constraints:</strong><br />1 &lt;= n &lt;= 100</span></p>", "contributor": "Ayush Govil", "test_cases": "2&!//!&1 2\n3 4&!//!&3 4\n2 1", "article_existence": 2, "article_list": ["https://www.geeksforgeeks.org/cpp-program-for-addition-of-two-matrices/", "https://www.geeksforgeeks.org/program-addition-two-matrices/"], "can_edit_history": false, "can_edit_problem": false, "can_edit_problem_read_only": false, "author": "ayush govil 1", "has_problem_solutions": true, "has_hints": true, "has_editorial": true, "can_view_hints": true, "track": "", "batch": "", "has_doubt_assistance": false, "extra": {"problem_languages": {"c": "C (gcc 5.4)", "cpp": "C++ (17)", "java": "Java (21)", "python3": "Python3", "csharp": "C#"}, "default_lang": null, "default_code": null, "initial_user_func": {"c": {"initial_code": "//Initial Template for C\r\n\r\n#include <stdio.h>\r\n\r\n//Position this line where user code will be pasted.\r\n\r\nint main()\r\n{\r\n    int tc;\r\n\tscanf(\"%d\", &tc);\r\n\twhile(tc--){\r\n\t\tint n;\r\n\t\tscanf(\"%d\", &n);\r\n\t\tint matrixA[n][n];\r\n\t\tint matrixB[n][n];\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 0; j < n; j++){\r\n\t\t\t\tscanf(\"%d\", &matrixA[i][j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 0; j < n; j++){\r\n\t\t\t\tscanf(\"%d\", &matrixB[i][j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tAddition(n, matrixA, matrixB);\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 0; j < n; j++)\r\n\t\t\t\tprintf(\"%d \", matrixA[i][j]);\r\n\t\t\tprintf(\"\\n\");\r\n\t\t}\r\n\t\nprintf(\"~%s\", \"\\n\");}\r\n\treturn 0;\r\n}", "user_code": "// User function Template for C\n\nvoid Addition(int n, int matrixA[][n], int matrixB[][n]) {}", "created_at_timestamp": 1618490254.0, "updated_at_timestamp": 1764918402.0}, "cpp": {"initial_code": "//Initial Template for C++\r\n\r\n#include<bits/stdc++.h>\r\nusing namespace std;\r\n//Position this line where user code will be pasted.\r\nint main(){\r\n\tint tc;\r\n\tcin >> tc;\r\n\twhile(tc--){\r\n\t\tint n;\r\n\t\tcin >> n;\r\n\t\tvector<vector<int>> matrixA(n, vector<int>(n,0));\r\n\t\tvector<vector<int>> matrixB(n, vector<int>(n,0));\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 0; j < n; j++){\r\n\t\t\t\tcin >> matrixA[i][j];\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 0; j < n; j++){\r\n\t\t\t\tcin >> matrixB[i][j];\r\n\t\t\t}\r\n\t\t}\r\n\t\tSolution ob;\r\n\t\tob.Addition(matrixA, matrixB);\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 0; j < n; j++)\r\n\t\t\t\tcout << matrixA[i][j] <<\" \";\r\n\t\t\tcout << \"\\n\";\r\n\t\t}\r\n\t\ncout << \"~\" << \"\\n\";\n}\r\n\treturn 0;\r\n}", "user_code": "// User function Template for C++\n\nclass Solution {\n  public:\n    void Addition(vector<vector<int>>& matrixA, vector<vector<int>>& matrixB) {\n        // Code here\n        \n    }\n};", "created_at_timestamp": 1618490254.0, "updated_at_timestamp": 1764918402.0}, "java": {"initial_code": "//Initial Template for Java\r\n\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\nclass GFG\r\n{\r\n    public static void main(String[] args) throws IOException\r\n    {\r\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n        int T = Integer.parseInt(br.readLine().trim());\r\n        while(T-->0)\r\n        {\r\n            int n = Integer.parseInt(br.readLine().trim());\r\n            int[][] matrixA = new int[n][n];\r\n            int[][] matrixB = new int[n][n];\r\n            for(int i = 0; i < n; i++){\r\n                String[] S = br.readLine().trim().split(\" \");\r\n                for(int j = 0; j < n; j++)\r\n                    matrixA[i][j] = Integer.parseInt(S[j]);\r\n            }\r\n            for(int i = 0; i < n; i++){\r\n                String[] S = br.readLine().trim().split(\" \");\r\n                for(int j = 0; j < n; j++)\r\n                    matrixB[i][j] = Integer.parseInt(S[j]);\r\n            }\r\n            Solution ob = new Solution();\r\n            ob.Addition(matrixA, matrixB);\r\n            for(int i = 0; i < n; i++){\r\n                for(int j = 0; j < n; j++){\r\n                    System.out.print(matrixA[i][j] + \" \");\r\n                }\r\n                System.out.println();\r\n            }\r\n        }\r\n    }\r\n}\r\n", "user_code": "// User function Template for Java\n\nclass Solution {\n    public void Addition(int[][] matrixA, int[][] matrixB) {\n        // code here\n        \n    }\n}", "created_at_timestamp": 1618490254.0, "updated_at_timestamp": 1764918402.0}, "python3": {"initial_code": "#Initial Template for Python 3\r\n\r\nif __name__ == '__main__':\r\n\tT=int(input())\r\n\tfor i in range(T):\r\n\t\tn = int(input())\r\n\t\tmatrixA = []\r\n\t\tmatrixB = []\r\n\t\tfor _ in range(n):\r\n\t\t\tmatrixA.append(list(map(int,input().split())))\r\n\t\tfor _ in range(n):\r\n\t\t\tmatrixB.append(list(map(int,input().split())))\r\n\t\tob = Solution()\r\n\t\tob.Addition(matrixA, matrixB)\r\n\t\tfor i in range(n):\r\n\t\t\tfor j in range(n):\r\n\t\t\t\tprint(matrixA[i][j], end = \" \")\r\n\t\t\tprint()", "user_code": "#User function Template for python3\n\nclass Solution:\n\tdef Addition(self, matrixA, matrixB):\n\t\t# Code here", "created_at_timestamp": 1618490254.0, "updated_at_timestamp": 1764918402.0}, "csharp": {"initial_code": "// Initial Template for C#\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace DriverCode {\n\nclass GFG {\n    static void Main(string[] args) {\n        int testcases; // Taking testcase as input\n        testcases = Convert.ToInt32(Console.ReadLine());\n        while (testcases-- > 0) // Looping through all testcases\n        {\n            int N = Convert.ToInt32(Console.ReadLine());\n\n            List<List<int>> matrixA = new List<List<int>>();\n            for (int i = 0; i < N; i++) {\n                matrixA.Add(new List<int>());\n            }\n\n            for (int i = 0; i < N; i++) {\n                var elements = Console.ReadLine().Trim().Split(' ');\n                for (int j = 0; j < N; j++) {\n                    matrixA[i].Add(int.Parse(elements[j]));\n                }\n            }\n\n            List<List<int>> matrixB = new List<List<int>>();\n            for (int i = 0; i < N; i++) {\n                matrixB.Add(new List<int>());\n            }\n            for (int i = 0; i < N; i++) {\n                var elements = Console.ReadLine().Trim().Split(' ');\n                for (int j = 0; j < N; j++) {\n                    matrixB[i].Add(int.Parse(elements[j]));\n                }\n            }\n\n            Solution obj = new Solution();\n            obj.Addition(matrixA, matrixB);\n\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < N; j++) {\n                    Console.Write(matrixA[i][j] + \" \");\n                }\n                Console.Write(\"\\n\");\n            }\n\n            Console.Write(\"~\" + \"\\n\");\n        }\n    }\n}\n}", "user_code": "// User function Template for C#\n\nclass Solution {\n    // Complete this function\n    public void Addition(List<List<int>> matrixA, List<List<int>> matrixB) {\n        // Your code here\n        \n    }\n}", "created_at_timestamp": 1702897666.0, "updated_at_timestamp": 1764918402.0}}, "input": "2&!//!&1 2\n3 4&!//!&3 4\n2 1", "input_format": {"arguments": "n=&!//!&a[][]=&!//!&b[][]", "datatype": "INTEGER&!//!&INTEGER_2D_ARRAY&!//!&INTEGER_2D_ARRAY"}, "is_mtc_enabled": false}, "course_default_lang": null, "interview_links": [], "user_has_access_to_doubt_assistance": false, "editorial_type": "post", "associated_func_pid": null, "can_view_author_solution": false, "show_editorial_tab": true, "is_todays_potd": false, "visualizer_type": null, "input_format": {"arguments": "n=&!//!&a[][]=&!//!&b[][]", "datatype": "INTEGER&!//!&INTEGER_2D_ARRAY&!//!&INTEGER_2D_ARRAY"}}, "status": true}