c++ make sure the printed array is of the int the user entered not just a mutipl
ID: 3863072 • Letter: C
Question
c++ make sure the printed array is of the int the user entered not just a mutiplcation table
Final Proficiency Demonstrations You will fill/initialize a two-dimensional array to contain multiples based on the row, column, and a number from the user. For example, this is a 3 times 3 array filled with multiples based on the row, column and the number 1 from the user. 1 2 3 2 4 6 3 6 9 Write a program to create a 5 times 5 two-dimensional array on the stack: - Get an integer number from the user - Write a function, void fun(int a[][5], int size, int num), to: - Fill the array with multiples of num based on the row and number from the user - Print the array to the screen.Explanation / Answer
#include <iostream>
using namespace std;
void fun(int a[][5], int size, int num) {
for(int i=0; i<size; i++){
for(int j=0; j<5; j++){
a[i][j]= (i+1)*(j+1)*num;
}
}
}
int main()
{
int num;
int a[5][5];
cout<<"Enter the number: ";
cin >> num;
fun(a,5,num);
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Output:
sh-4.2$ g++ -std=c++11 -o main *.cpp
sh-4.2$ main
Enter the number: 1
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.