8.
#include<iostream>
using namespace std;
int main()
{
void change(int &,int &);
int a,b;
cin>>a>>b;
if(a<b) change(a,b);
cout<<a<<" "<<b<<" "<<endl;
return 0;
}
void change(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
9.
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
void change(int &,int &);
if(a>b) change(a,b);
if(a>c) change(a,c);
if(b>c) change(b,c);
cout<<a<<" "<<b<<" "<<c<<" "<<endl;
return 0;
}
void change(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
10.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s1,s2;
s1="week";
s2="end";
cout<<"s1 = "<<s1<<endl;
cout<<"s2 = "<<s2<<endl;
s1=s1.append(s2);
cout<<"s1 = "<<s1<<endl;
return 0;
}
11.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
int i,n;
char temp;
cin>>str;
n=str.size();
for(i=0;i<n/2;i++)
{
temp=str[i];
str[i]=str[n-i-1];
str[n-i-1]=temp;
}
cout<<str<<endl;
return 0;
}
12.
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string str[5]={"BASIC","C","C++","FORTRAN","PASCAL"};
void sort(string[]);
sort (str);
for(i=0;i<5;i++)
cout<<str[i]<<" ";
cout<<endl;
return 0;
}
void sort(string s[])
{
int i,j;
string t;
for(j=0;j<5;j++)
for(i=0;i<5-j;i++)
if(s[i]>s[i+1])
{
t=s[i];
s[i]=s[i+1];
s[i+1]=t;
}
13.
#include<iostream>
#include<string>
using namespace std;
int main()
{
int a[5]={1,10,-3,7,2};
float b[5]={1.7,4.9,3.6,7.9,-9.1};
long c[5]={110221,-123574,1190876,-12980,2643};
void sort(int a[]);
void sort(float b[]);
void sort(long c[]);
sort(a);
sort(b);
sort(c);
return 0;
}
void sort(int a[])
{
int i,j,t;
for(j=0;j<4;j++)
for(i=0;i<4;i++)
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
cout<<"i_sort= ";
for(i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
void sort(float a[])
{
int i,j;
float t;
for(j=0;j<4;j++)
for(i=j+1;i<5;i++)
if(a[j]>a[i])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}
cout<<"f_sort= ";
for(i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
void sort(long a[])
{
int i,j;
long t;
for(j=0;j<4;j++)
for(i=0;i<4-j;i++)
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
cout<<"l_sort= ";
for(i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}