Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Print a single digit number and print a rectangular form of 4 columns and 6 rows

C++ Basic: Exercise-31 with Solution

Write a program in C++ to input a single digit number and print a rectangular form of 4 columns and 6 rows.

Pictorial Presentation:

C++ Exercises: Input a single digit number and print in such a rectangular form that it gots 4 columns and 6 rows

Sample Solution:

C++ Code :

#include <iostream>
using namespace std;

    int main()
    {
    	int x;
		cout << "\n\n Make a rectangular shape by a single digit number :\n";
		cout << "--------------------------------------------------------\n";		
        cout<<" Input the number : ";
    	cin>> x;
        cout<<" "<<x<<x<<x<<x<<endl;
        cout<<" "<<x<<" "<<" "<<x<<endl;
        cout<<" "<<x<<" "<<" "<<x<<endl;
        cout<<" "<<x<<" "<<" "<<x<<endl;
        cout<<" "<<x<<" "<<" "<<x<<endl;        
        cout<<" "<<x<<x<<x<<x<<endl;        
        cout << endl;
        return 0;
    }

Sample Output:

 Make a rectangular shape by a single digit number :                   
--------------------------------------------------------               
 Input the number : 5                                                  
 5555                                                                  
 5  5                                                                  
 5  5                                                                  
 5  5                                                                  
 5  5                                                                  
 5555     

Flowchart:

Flowchart: Print a single digit number and print in such a rectangular form that it gots 4 columns and 6 rows

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to compute the total and average of four numbers.
Next: Write a program in C++ to check whether a number is positive, negative or zero.

What is the difficulty level of this exercise?