|
| 1 | +#include<iostream> |
| 2 | +#include<iomanip> //Required for these manipulators |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +int main() |
| 6 | +{ |
| 7 | + int i; |
| 8 | + cout<<"Enter a number = "; |
| 9 | + cin>>i; // or cin>>hex>>i; to get hexadecimal input only |
| 10 | + cout<<"Hexadecimal value = "<<hex<<i<<endl; // 1.endl Manipulator:For next line |
| 11 | + cout<<"Octal value = "<<oct<<i<<endl; // 2.hex,dec,oct for converting base to hexadecimal(16),octal(8),decimal(10) |
| 12 | + cout<<"Decimal value = "<<dec<<i<<endl; |
| 13 | + cout<<"Enter hexadecimal number = "; |
| 14 | + cin>>setbase(16)>>i; // 3.setbase(b) simailar to above toset base to hex, dec or oct |
| 15 | + cout<<setw(27)<<"Hexadecimal value = "<<setbase(16)<<i<<endl; //4.setw() used to set the width of chacters in program |
| 16 | + cout<<setw(27)<<"Octal value = "<<setbase(8)<<i<<endl; |
| 17 | + cout<<setw(27)<<"Decimal value = "<<setbase(10)<<i<<endl; |
| 18 | + int age=22,rollno=076; |
| 19 | + cout<<setfill('#'); |
| 20 | + cout<<"Age"<<endl; |
| 21 | + cout<<setw(4)<<age<<endl; |
| 22 | + cout<<"Roll No"<<endl; |
| 23 | + cout<<setw(4)<<rollno<<endl; |
| 24 | + |
| 25 | + // float a=129.455396; |
| 26 | + // cout<<"Float with 2 precision = "<<setprecision(2)<<a<<endl; //setprecision used to set precision of decimal numbers |
| 27 | + // cout<<"Float with 4 precision = "<<setprecision(4)<<a<<endl; |
| 28 | + // cout<<"Float with 6 precision = "<<setprecision(6)<<a<<endl; |
| 29 | + |
| 30 | +return 0; |
| 31 | +} |
| 32 | + |
0 commit comments