1,输入整数显示十六进制和八进制
#include<iostream>
using namespace std;
int main()
{
int n,l;
cin>>n;
n>=0?l=n:l=-n;
if(n>=0)
{
cout<<l<<" "<<hex<<l<<" "<<oct<<l<<endl;
}
else
{
cout<<"-"<<l<<"-"<<hex<<l<<"-"<<oct<<l<<endl;
}
return 0;
}
2,输入字符显示ASCII值
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
char ch;
ch=cin.get();
cout<<ch+0<<endl;
return 0;
}
3,显示hello world!
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!"<<endl;
return 0;
}
4,显示n个字符
#include <iostream>
using namespace std;
int main()
{
int k;
char ch;
cin >>k>>ch;
for (int i=0;i<k;i++)
cout<<ch;
return 0;
}
5,显示唐诗
#include<iostream>
using namespace std;
int main()
{
cout<<"慈母手中线"<<endl;
cout<<"游子身上衣"<<endl;
cout<<"临行密密缝"<<endl;
cout<<"意恐迟迟归"<<endl;
cout<<"谁言寸草心"<<endl;
cout<<"报得三春晖"<<endl;
return 0;
}