Write a C++ code for the following pattern display using ios classes. The precision is set according to the value of variable x. (use setprecision(), setwidth(), setfill() ios flags and functions).
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int x = 0;
cout << "Set precision: ";
cin >> x;
cout << fixed << setprecision(x);
cout << "Now double number 2.3 as: " << 2.3 << endl;
cout << "Set width ('Hello' will be right - aligned with a padding of x) : ";
cin >> x;
cout << setw(x);
cout << "Hello" << endl;
cout << "Set fill ('Hello' will be right - aligned, indented by x, all spaces will be replaced with the entered character.)(char): ";
char ch;
cin >> ch;
cout << setfill(ch);
cout << setw(x) << "Hello" << endl;
return 0;
}
Comments
Leave a comment