Question

C Thank You for You x Home - OwNet x B Assignment 401 X CPP-A01 - Dynam x ASM-103 - Intege X ASM-A03 - Integex Calculus - FinC Thank You for You x Home - OwNet x B Assignment 401 X CPP-A01 - Dynam x ASM-103 - Intege X ASM-A03 - Integex Calculus - FinC Thank You for You x Home - OwNet x B Assignment 401 X CPP-A01 - Dynam x ASM-103 - Intege X ASM-A03 - Integex Calculus - Fin

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

Hi,

Please refer screenshots for more clarity..

I've used double pointer and setw for setting width for printing in this code.. Please go through it..

C++ code:

//program starts here..

#include <iostream>
#include<stdlib.h>
#include<iomanip>
using namespace std;

int main() {
int row,col;
while(1)//while for validation
{
cout << "please enter the rows in the range of [1 to 10]:";
cin >> row;
if(row >= 1 && row <= 10)
break;
else
cout << "input not within the range[1 to 10]. Please Try again.." << endl;
}

while(1)//column validation
{
cout << "please enter the rows in the range of [1 to 10]:";
cin >> col;
if(col >= 1 && col <= 10)
break;
else
cout << "input not within the range[1 to 10]. Please Try again.." << endl;
}
int **arr = (int **)malloc(row * sizeof(int *));//allocating memory with row's size
//for each row one pointer
for(int i =0 ; i < row ; i++)
{
arr[i] = (int *)malloc(col * sizeof(int));//pointer to ith row ..
}
for(int i = 1 ; i <= row ; i++)
{
for(int j = 1; j <= col ; j++)
{
arr[i-1][j-1] = i*j;//multiplication and storing in 2D array
}
}
for(int i = 1; i <= col; i++)
{
cout << setw(3)<< " |" << i ;//setting width for each value and printing it
}
cout << endl;
for(int x = 1; x < col; x++)
{
cout << "-----*";
}
cout << endl;

for(int i = 0 ; i < row ; i++)
{
cout <<left <<setw(3) << i+1 ;//each row value
for(int j = 0; j < col ;j++)
{
cout <<"|" << setw(3)<< arr[i][j] ; //multiplication value
  
}
cout << endl;
for(int x = 1; x < col; x++)
{
cout << "-----*";//after each row, separator
}
cout << endl;
}
}

//End of the program

main.cpp saved #include <iostream> #include<stdlib.h> 3 #include<iomanip> using namespace std; int main() { int row,col; whilfor(int i = 1; i <= col; i++) 41 E cout << setw(3)<< 1 «i ;//setting width for each value and printing it 43 cout << endl;} ./main please enter the rows in the range of [1 to 10]:5, please enter the rows in the range of [1 to 10]:5 11 12 13 14 15} ./main please enter the rows in the range of [1 to 10]:-3, input not within the range[1 to 10]. Please Try again.. please e

If you have any doubts, please feel free to comment below..

Thank you..

Add a comment
Know the answer?
Add Answer to:
C Thank You for You x Home - OwNet x B Assignment 401 X CPP-A01 -...
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
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