打印菱形
#include<iostream> using namespace std; int main() { cout<<" *"<<endl; cout<<"***"<<endl; cout<<" *"<<endl; return 0; }
进制转换
#include<iostream> #include<iomanip> using namespace std; int main() { int a; cout<<"请任意输入一个十进制数:"; cin>>a; cout<<"八进制:"<<oct<<a<<"十六进制:"<<hex<<a<<endl; return 0; }
循环小数精度从小到大列出
#include<iostream> #include<iomanip> using namespace std; int main() { int number1,number2; cout<<"请输入两个数:"; cin>>number1>>number2; if(0==number2) { cout<<"请重新输入两个数:"; return 1; } double result=static_cast<double>(number1)/(number2); for(int precision=1;precision<=10;++precision) { cout<<"精度为"<<precision<<"的结果是:"; cout<<fixed<<setprecision(precision) <<result<<endl; } return 0; }