作业0327

P35 T7
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z);
cin>>a>>b>>c;
c=f(a,b,c);
cout<<c<<endl;
return 0;
}
int f(int x,int y,int z)
{
int m;
if(x>y)
m=x;
else m=y;
if (z>m)
m=z;
return(m);
}
T8
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if (x>y)
cout<<x<<","<<y<<endl;
else cout<<y<<","<<x<<endl;
return 0;
}


T9
#include <iostream>
using namespace std;
int main()
{
void sort(int x,int y,int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x,int y,int z)
{
int temp;
if(x>y)
{ temp=x;x=y;y=temp;}
if (z<x) cout<<z<<","<<x<<","<<y<<endl;
else if(z<y) cout<<x<<","<<z<<","<<y<<endl;
else cout<<x<<","<<y<<","<<z<<endl;




}
T10
#include<iostream>
#include<string.h>
using namespace std;
main()
{
  char a[20]="1234";
  char b[]="abcd";
  strcat(a,b);
  cout<<a<<endl;
}


T11
#include<iostream>
#include<string>
using namespace std;
int main()
{
 int i;
    string str;
    cout<<"请输入一串字符:"<<endl;
    cin>>str;
    cout<<"字符串倒序后为:"<<endl;
    for(i=str.length()-1;i>=0;i--)
    cout<<str[i];
    cout<<endl;   


 system("pause");
 return 0;
}
T12
#include <iostream> 
#include <string> 
using namespace std; 
int main() 

int i; 
string str[5]; 
void sort(string s[]); 
cout<<"Please input string:"<<endl; 
for(i=0;i<5;i++) 
cin>>str[i]; 
sort(str); 
cout<<"The sorted string is:"<<endl; 
for(i=0;i<=5;i++) 
cout<<str[i]<<" "; 
cout<<endl; 
return 0; 



void sort(string s[]) 

int i,j; 
string temp; 
for(i=0;i<4;i++) 
for(j=0;j<4-i;j++) 
if(s[j]>s[j+1]) 

temp=s[j]; 
s[j]=s[j+1];
s[j+1]=temp; 




T13
#include<iostream> 
using namespace std; 
template <typename Type> 
void sort(Type* cp); 
int main() 

int a[5]={1,9,0,23,-45}; 
float b[5]={2.4, 7.6, 5.5, 6.6, -2.3 }; 
long int c[5]={10100,-123567, 1198783,-165654, 3456}; 


sort(a); 
sort(b); 
sort(c);cin.get(); 
return 0; 



template <typename Type> 
void sort(Type* cp)

int i,j; 
Type temp; 
for(i=0;i<4;i++) 

for(j=0;j<4;j++) 

if(cp[j]>cp[j+1])
{temp=cp[j]; 
cp[j]=cp[j+1]; 
cp[j+1]=temp;} 


for(i=0;i<5;i++) 
cout<<cp[i]<<" "; 
cout<<endl; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值