小编Shu*_*rti的帖子

C++程序自动舍入除数组中第一个值之外的double值

我正在使用此代码进行函数重载,使用C++对double和整数数组进行排序.

 #include<iostream>
#include<bits/stdc++.h>
using namespace std;

void sort(int arr[],int n)
{
    int i,j,key;
    for(j=1;j<n;j++)
    {
        key=arr[j];
        i=j-1;
        while((i>=0)&&(arr[i]>key))
        {
            arr[i+1]=arr[i];
            i--;
        }
        arr[i+1]=key;
    }
    cout<<"Sorted integer array is \n";
    for(i=0;i<n;i++)
    {
        cout<<arr[i]<<endl;
    }
}

void sort(double arr[],int n)
{

    int i,j,key;
    for(j=1;j<n;j++)
    {
        key=arr[j];
        i=j-1;
        while((i>=0)&&(arr[i]>key))
        {
            arr[i+1]=arr[i];
            i--;
        }
        arr[i+1]=key;
    }
    cout<<"Sorted double array is \n";
    for(i=0;i<n;i++)
    {
        cout<<arr[i]<<endl;
    }
}

int main()
{
    int n;
    cout<<"Enter the size of the array \n";
    cin>>n;
    cout<<"Enter the values for the …
Run Code Online (Sandbox Code Playgroud)

c++ arrays double overloading function

0
推荐指数
1
解决办法
93
查看次数

标签 统计

arrays ×1

c++ ×1

double ×1

function ×1

overloading ×1