Question

In: Computer Science

Write a c++ function named multi_table to print out multiplication table for a given number of...

Write a c++ function named multi_table to print out multiplication table for a given number of rows and columns. Your program should print a header row and a header column to represent each row and column number. For example your function call multi_table(4, 4) would print below to the command line:

1 | 1 2 3 4

_________

2 | 2 4 6 8

3 | 3 6 9 12

4 | 4 8 12 16

Test your function in a driver program for 12 by 12 multiplication table.

Solutions

Expert Solution

code:

#include <iostream>
using namespace std;
int multi_table(int n,int m){       //passing parameters to multi_table function
int i,j,k;
for(i=1;i<=n;i++){ //loop for iterating through rows
       cout<<i<<"|";
for(j=1;j<=m;j++){ //loop for printing columns
   cout<<i*j<<" ";

}
cout<<"\n";
if(i==1){ //printing extra character "-" in column
               for(k=1;k<n*3;k++){
                   cout<<"-";  
               }
               cout<<"\n";
}
  
}
}

int main()
{
int n,m; //declaring variables n and m
cout<<"Enter no of rows:";
cin>>n; //taking no of rows from user
cout<<"Enter no of columns:";
cin>>m;
multi_table(n,m); //calling multi_table function
}

output:

output2:

code screenshot:


Related Solutions

Write a C++ function to print out all unique letters of a given string. You are...
Write a C++ function to print out all unique letters of a given string. You are free to use any C++ standard library functions and STL data structures and algorithms and your math knowledge here. Extend your function to check whether a given word is an English pangram (Links to an external site.). You may consider your test cases only consist with English alphabetical characters and the character.
Q9) Write a function that asks the user for a number and prints out the multiplication...
Q9) Write a function that asks the user for a number and prints out the multiplication table for that number. Python3 Q10)Write a function that takes two integer inputs for width and length, and prints out a rectangle of stars. (Use * to represent a star). Q11)Write a program that reads in a string and prints whether it: [Hint: given a character like ‘H’ you can apply to it the method ‘H’.isalpha() to check if it is a letter or...
Write a C++ function to print any given std::array of a given type to the standard...
Write a C++ function to print any given std::array of a given type to the standard output in the form of {element 0, element 1, element 2, ...}. For example given the double array, d_array = {2.1, 3.4, 5.6, 2.9}, you'd print {2.1, 3.4, 5.6, 2.9} to the output upon executing std::cout << d_array; line of code. Your function mus overload << operator.
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
Write a function such that given a number N, display the N*N multiplication matrix from 1...
Write a function such that given a number N, display the N*N multiplication matrix from 1 to N. Then, write a C++ program such that, it prints the multiplication matrices of numbers 1,4,7, and 10 using a loop concept. Check the sample output below, to see how the program should work. Make sure to have your output exactly the same as the below output.
Write a program that uses nested for loops to print a multiplication table. Your program should...
Write a program that uses nested for loops to print a multiplication table. Your program should print out the multiplication table starting a 1 and going to 12. Output should be like: 1 x 1 = .1 x 2 = 2
Write a C++ program to print all the perfect numbers below a certain given number. A...
Write a C++ program to print all the perfect numbers below a certain given number. A perfect number is a number that that is equal too the sum of it's divisors other than itself . For example, 6 and 28 are all perfect numbers. 6 = ( 1+2 +3) 28 = (1+2+4+7+14) Make sure your program conforms to the following requirements: 1. Accept the upper limit from the user (as an integer). 2. Make sure the number is positive (at...
#python #code #AP class #Tech write a function code script which will print out number pyramid...
#python #code #AP class #Tech write a function code script which will print out number pyramid in the form of * so the output will be made up of **** resting on top of each other to form a pyramid shape. Bottom layer should be made of 5 multiplication signs like ***** then next 4 multiplication signs and so on. Top part should have only one *
Write a recursive function to calculate and return factorial of a given number 'n'. in C...
Write a recursive function to calculate and return factorial of a given number 'n'. in C progrmaining
Exercise 1. Write a function named printBox to print a 5 x 10 box of asterisks...
Exercise 1. Write a function named printBox to print a 5 x 10 box of asterisks using nested loops. When printBox() is called your function should display the pattern shown below. Write a function named printBox to print a 5 x 10 box of asterisks using nested loops. When printBox() is called your function should display the following information. ********** ********** ********** ********** ********** """ # place the code for the printBox function here printBox( numRows, numCols ) Exercise 2....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT