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:
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:
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?