沐沐Mnn 2019-04-28 11:58 采纳率: 72.7%
浏览 409
已采纳

C++编程填空问题:反转

描述

补充代码,使得程序输出为

50 4 34 21 10

7.1 8.1 9.1 10.1 11.1 4.1

#include<iostream>
using namespace std;
template<class T>
// 在此处补充你的代码
int main()
{
    int a[5] = { 10, 21, 34, 4, 50 };
    double d[6] = { 4.1, 11.1, 10.1, 9.1, 8.1, 7.1 };
    f(a, 5);
    f(d, 6);
    for (int i = 0; i < 5; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    for (int j = 0; j < 6; j++)
    {
        cout << d[j] << " ";
    }
    cout << endl;
    return 0;
}

样例输入

样例输出

50 4 34 21 10
7.1 8.1 9.1 10.1 11.1 4.1

http://cxsjsx.openjudge.cn/2018midexamcloze/5/

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-04-28 12:54
    关注
    // Q759045.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    
    #include<iostream>
    using namespace std;
    template<class T>
    // 在此处补充你的代码
    void f(T arr[], int n)
    {
        for (int i = 0; i < n / 2; i++)
        {
            T t = arr[i];
            arr[i] = arr[n - 1 - i];
            arr[n - 1 - i] = t;
        }
    }
    int main()
    {
        int a[5] = { 10, 21, 34, 4, 50 };
        double d[6] = { 4.1, 11.1, 10.1, 9.1, 8.1, 7.1 };
        f(a, 5);
        f(d, 6);
        for (int i = 0; i < 5; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
        for (int j = 0; j < 6; j++)
        {
            cout << d[j] << " ";
        }
        cout << endl;
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错