Question

Part I: Code writing: 1. 3pts (Display matrix of numbers) Write a function that displays an n-by-n matrix using the following

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

Code:

#include<stdio.h>
#include<stdlib.h>

void printMatrix(int n){
int i=0,j=0; //Variables for iterations
for(i=0;i<n;i++){ // Loop for n-Rows
for(j=0;j<n;j++){ // Loop for n-Columns
// We get minimum of mod 7 is 0, then 0+3 when it is 0 for "rand()%7"
// We get maximum of mod 7 is 6, then 6+3 when it is 6 for "rand()%7"
printf("%d ",(rand()%(7))+3); // Printing random number in between 3 and 9
}
printf("\n"); // Printing New line
}
}
int main(){
int n=0;
printf("Enter n: ");
scanf("%d",&n);
printMatrix(n);
return 0;
}

Screenshots:

1 #include<stdio.h> #include<stdlib.h> 4 void printMatrix(int n){ int i=0,j=0; //Variables for iterations for(i=0;i<n;i++){ /

Output:

Enter n: 2 4 7 58

Add a comment
Know the answer?
Add Answer to:
Part I: Code writing: 1. 3pts (Display matrix of numbers) Write a function that displays an...
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
  • Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a...

    Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a method that computes and returns the area of a square using the following header: public static double area ( double side) Write a main method that prompts the user to enter the side of a square, calls the area method then displays the area. Question 1a: Write a method that converts miles to kilometers using the following header: public static double convertToKilometers (double miles)...

  • Write the PYTHON code that displays the following numbers: The program should have a header that...

    Write the PYTHON code that displays the following numbers: The program should have a header that displays "Number   Doubled Tripled" above the start of the numbers. If putting all numbers on the same line, then they will need to be separated so you can see he individual number.(https://www.programiz.com/python-programming/methods/built-in/print) The program should display Every whole number from 1 through 35. The program should display that number doubled. The program should also display that number tripled. Make a working version of this...

  • Use a C++ program to run your code that prompts the user to enter an integer,...

    Use a C++ program to run your code that prompts the user to enter an integer, greater or equal to 2, and displays its largest factor other than itself. To answer for this question, It is required that you use following two functions to complete the assignment. a.     // Prompts the user to enter an integer: number >=2         void getNumber( int& number); b.     // returns the largest factor of n other than itself         int getLargestNonSelfFactor(int n);

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • Write a method that will display numbers from 1 to n with 10 numbers per line....

    Write a method that will display numbers from 1 to n with 10 numbers per line. The numbers are separated by one space. The method header is as follows: public static void displayNumbers(int n)

  • Write a method to multiply two matrices. The header of the method is: public static double[][]...

    Write a method to multiply two matrices. The header of the method is: public static double[][] multiplyMatrix(double[][] a, double[][] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element is For example, for...

  • USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a...

    USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a 3 a14 1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 QUESTION II: An approximate value of a number can be computed using the following formula: 7 ) Write a program that displays the result of 4 X + 7 • H) and 4 X - 를 7 tis). 9 QUESTION III: Write a program that prompts...

  • Write an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student’s score. At the...

  • Using PYTHON: (Find the index of the smallest element) Write a function that returns the index...

    Using PYTHON: (Find the index of the smallest element) Write a function that returns the index of the smallest element in a list of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: def indexOfSmallestElement(lst): Write a test program that prompts the user to enter a list of numbers, invokes this function to return the index of the smallest element, and displays the index. PLEASE USE LISTS!

  • C++ Recursion Code a function which displays the first n prime numbers. The prototype is: void...

    C++ Recursion Code a function which displays the first n prime numbers. The prototype is: void prime (int) The number of primes to display is passed as the parameter. The function prime itself is not recursive. However, it should call a separate recursive helper function which determines if a given number is prime #include <iostream> using namespace std; void prime(int ) { } int main() {    prime (21);    return 0; }

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