fork(8) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void printGrid(int &userRows, int &userColumns){
  5. cout<<endl;
  6. cout<<" ";
  7. int i=1,j;
  8. for(j = 0; j <= 4*userColumns; j++){
  9. if(j%4==2)
  10. cout<<i++;
  11. else cout<<" ";
  12. }
  13. cout<<endl;
  14. for(i = 0; i <= 2*userRows; i++){
  15. if(i%2!=0)
  16. cout<<(char)(i/2 +'A');
  17. for(j = 0; j <= 2*userColumns; j++){
  18. if(i%2==0)
  19. {
  20. if(j==0)
  21. cout<<" ";
  22. if(j%2==0)
  23. cout<<" ";
  24. else cout<<"---";
  25. }
  26. else{
  27. if(j%2==0)
  28. cout<<"|";
  29. else cout<<" ";
  30. }
  31. }
  32. if(i%2!=0)
  33. cout<<(char)(i/2 +'A');
  34. cout<<endl;
  35. }
  36. cout<<" ";
  37. for(j = 0, i = 1; j <= 4*userColumns; j++){
  38. if(j%4==2)
  39. cout<<i++;
  40. else cout<<" ";
  41. }
  42. cout<<endl;
  43. }
  44.  
  45. int main() {
  46. int userRows, userColumns;
  47. cout << "Enter the number of rows -> ";
  48. cin >> userRows;
  49. cout << "\nEnter the number of columns -> ";
  50. cin >> userColumns;
  51. printGrid(userRows, userColumns);
  52. return 0;
  53. }
Success #stdin #stdout 0s 4544KB
stdin
4
6
stdout
Enter the number of rows -> 
Enter the number of columns -> 
   1   2   3   4   5   6  
  --- --- --- --- --- --- 
A|   |   |   |   |   |   |A
  --- --- --- --- --- --- 
B|   |   |   |   |   |   |B
  --- --- --- --- --- --- 
C|   |   |   |   |   |   |C
  --- --- --- --- --- --- 
D|   |   |   |   |   |   |D
  --- --- --- --- --- --- 
   1   2   3   4   5   6