1、 请输入高度h,输入一个高为h,上底边长为h的等腰梯形(例如h=4,图形如下)。
****
******
********
**********


1 #include<iostream> 2 using namespace std; 3 4 int main(){ 5 int h; 6 cout<<"please input a num of heigh"<<endl; 7 cin>>h; 8 int max=h+2*(h-1); 9 for(int i=0;i<h;i++){ 10 int num=h+i*2; 11 int blank=(max-num)/2; 12 for(int j=0;j<blank;++j)cout<<" "; 13 for(int k=0;k<num;k++)cout<<"*"; 14 cout<<endl; 15 } 16 return 0; 17 }//main
2、 请编写一个程序,从键盘上输入n(n的范围是1~20),求n的阶乘。


1 #include<iostream> 2 using namespace std; 3 4 int main(){ 5 int n; 6 cout<<"please input a num 1-20"<<endl; 7 cin>>n; 8 double res=1;//用int会溢出 9 for(int i=1;i<=n;i++)res*=i; 10 cout<<res<<endl; 11 12 return 0; 13 }//main
3、 从键盘上任意输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到大进行排序,请输出排序后的结果。


1 #include<iostream> 2 #include<string> 3 using namespace std; 4 #include<algorithm> 5 6 7 8 int main(){ 9 string s; 10 cout<<"please input a string "<<endl; 11 cin>>s; 12 sort(s.begin(),s.end()); 13 cout<<s<<endl; 14 return 0; 15 }//