當前位置:編程學習大全網 - 編程軟體 - C++編程 利用重載

C++編程 利用重載

#include <iostream>

using namespace std;

#define N 5

void sort(int a[])

{

for (int i=0;i<N;i++)

for (int j=0;j<N;j++)

{

if(a[i]<a[j])

{

int temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

void sort(float a[])

{

for (int i=0;i<N;i++)

for (int j=0;j<N;j++)

{

if(a[i]<a[j])

{

float temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

void sort(double a[])

{

for (int i=0;i<N;i++)

for (int j=0;j<N;j++)

{

if(a[i]<a[j])

{

double temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

int main()

{

int a[]={3,6,89,7,8};

float b[]={1.1,3.6,5.9,8.9,0.3};

double c[]={56.4,68.7,65.5,33.9,97.8};

sort(a);sort(b);sort(c);

for (int i=0;i<N;i++)

cout<<a[i]<<' ';

cout<<endl;

for (int i=0;i<N;i++)

cout<<b[i]<<' ';

cout<<endl;

for (int i=0;i<N;i++)

cout<<c[i]<<' ';

cout<<endl;

return 0;

}

  • 上一篇:大數據學起來難嗎?
  • 下一篇:怎樣制作生物細胞模型、跪求···
  • copyright 2024編程學習大全網