Question

Homework 4 Files to submit: mat add.c Time it took Matthew to Complete: 10 mins IN C All programs must compile without warnings when using the-Wall and-Werror options Submit only the files requested Your program must match the output exactly to receive credit. Make sure that all prompts and output match mine exactly. o Easiest way to do this is to copy and paste them All input will be valid unless stated otherwise Print all real numbers to two decimal places unless otherwise stated . The examples provided in the prompts do not represent all possible input you can receive. All inputs in the examples in the prompt are underlined You dont have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program o If you have questions please post them on Piazza . Restrictions No global variables are allowed Your main function may only declare variables, call other functions, and assign variables values.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<stdio.h>
#include<stdlib.h>

void printMatrix(int **A, int n, int m) {
   int i = 0, j = 0;
   while(i<n){
      j = 0;
      while(j<m) {
         printf("%d ", A[i][j]);
         j++;
      }
      printf("\n");
      i++;
   }
   printf("\n");

}

int** makeMatrix(int n, int m) {
   int i = 0;
   int** A = (int**)malloc(sizeof(int*)*n);
   while(i<n){
      A[i] = (int*)malloc(sizeof(int)*m);
      i++;
   }
   return A;
}

void main() {
   int A[10][10];
   int B[10][10];
   int i = 0,j = 0,n, m;
   int** sum;
   printf("Enter number of rows: ");
   scanf("%d",&n);
   printf("Enter number of columns: ");
   scanf("%d",&m);
   sum = makeMatrix(n,m);
   printf("Enter matrix A: \n");
   while(i<n){
      j = 0;
      while(j<m) {
         scanf("%d", &A[i][j]);
         j++;
      }
      i++;
   }
   printf("Enter matrix B: \n");
   i = 0;
   while(i<n){
      j = 0;
      while(j<m) {
         scanf("%d", &B[i][j]);
         j++;
      }
      i++;
   }
   i = 0;
   while(i<n){
      j = 0;
      while(j<m) {
         sum[i][j] = A[i][j] + B[i][j];
         j++;
      }
      i++;
   }
   printf("\nA+B:\n");
   printMatrix(sum,n, m);
}

\color{blue}Please\; up\;vote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
Homework 4 Files to submit: mat add.c Time it took Matthew to Complete: 10 mins IN...
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
  • Requriements: Submit only the files requested Print all floats to 2 decimal points unless stated otherwise...

    Requriements: Submit only the files requested Print all floats to 2 decimal points unless stated otherwise Descripition : For this problem you will be implementing a Caesarin Cipher. A Caesarin Cipher takes a string and a shift amount and shift the characters in the string by the shift amount. Specifications: Only characters should be ciphered If a character is shifted beyond the end of the aphabet it should wrap back around For example if the letter 'y' is shifted 3...

  • The files must be called Proper coding conventions required the first letter of the class start...

    The files must be called Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter. Only submit the .java file needed to make the program run. Do not submit the .class file or any other file. 5% Style Components Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892....

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • Files, Pointers and Dynamic Memory Allocation, and Structs Due date/time: Tuesday, Nov 26th, 11:00 PM. WRITE...

    Files, Pointers and Dynamic Memory Allocation, and Structs Due date/time: Tuesday, Nov 26th, 11:00 PM. WRITE A C++ PROGRAM (USE DYNAMIC MEMORY ALLOCATION) THAT READS N CUSTOMER RECORDS FROM A TEXT FILE (CUSTOMERS.TXT) SUCH THAT THE NUMBER OF THE RECORDS IS STORED ON THE FIRST LINE IN THE FILE. EACH RECORD HAS 4 FIELDS (PIECES OF INFORMATION) AND STORED IN THE FILE AS SHOWN BELOW: Account Number (integer) Customer full name (string) Customer email (string) Account Balance (double) The program...

  • C Programming QUESTION 9 Write a program that prompts for and reads four integer input values,...

    C Programming QUESTION 9 Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style. Your program will calculate and print a new value based on the command that's entered, as follows: 'A' or 'a': Calculate the average of the four input values 'S' or 's': Calculate...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • I need help with this code, I'm stuck on it, please remember step 4, I'm very...

    I need help with this code, I'm stuck on it, please remember step 4, I'm very much stuck on that part. It says something about putting how many times it appears Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...

  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • Lab 10: ArrayLists and Files in a GUI Application For this lab, you will work on...

    Lab 10: ArrayLists and Files in a GUI Application For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, DrawTextItem, DrawTextPanel, and SimpleFileChooser) in the code directory. These files are supposed to be in package named "textcollage". Start an Eclipse project, create a package named textcollage in that project, and copy the four files into the package. To run the program, you should run the file TextCollage.java, which...

  • Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity...

    Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity to practice functions, functions that call other functions, reference variables, logical statements (what is meant by logical statement is a statement such as if, if/else if, switch), and input validation, HW7 (Graded out of 100) A talent competition has 5 judges, each of whom awards a score between 0 and 10 for each performer. Fractional scores, such as 8.3, are allowed. A performer's final...

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