Array in Function

Write C++ program tell the user
Press 1 to change Row to Row and change (using Function ) output like that :
1 1 1
2 2 2
3 3 3
and press 2 to change Row to Col and change (using function) output like that :
1 2 3
1 2 3
1 2 3
and press 0 to End the Program

Showing Answers 1 - 1 of 1 Answers

mayank

  • Sep 7th, 2016
 

Code
  1. #include <iostream>

  2.  

  3. using namespace std;

  4.  

  5. void rowtorow()

  6. {

  7.     for(int i=0;i<3;++i)

  8.     {

  9.         for(int j=0;j<3;++j)

  10.         {

  11.             cout<<i+1<<" ";

  12.         }

  13.         cout<<"

  14. ";

  15.     }

  16. }

  17. void rowtocol()

  18. {

  19.     for(int i=0;i<3;++i)

  20.     {

  21.         for(int j=0;j<3;++j)

  22.         {

  23.             cout<<j+1<<" ";

  24.         }

  25.         cout<<"

  26. ";

  27.     }

  28. }

  29. void close(){

  30.  

  31. }

  32.  

  33. typedef void (*fp)();

  34. int main()

  35. {

  36.     const fp arr[3]={close,rowtorow,rowtocol};

  37.     int i;

  38.     cout<< " enter the number 0,1,or 2:";

  39.     cin>>i;

  40.     arr[i]();

  41.  

  42.     cout << "

  43. Hello world!" << endl;

  44.     return 0;

  45. }

  46.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions