m0_61828817 2021-11-03 22:01 采纳率: 70%
浏览 45
已结题

不会写这个c语言,翻译时//main那往回不翻译,帮帮忙

Write a function named copy_arr(source, target, length) to copy the contents of an array-of-double to another array.
Write another function named sort(array, length) to sort the array passed by parameter in descending order.(降序排序,从大到小)
Write a main() function that initializes the array-of-double and then call copy_arr() to make the copy, and show all the element-values of the copied array . Then call the sort() function , and show all the element-values of the sorted array.
Using the following main() function for test your functions.

//main(),不要修改
int main(){
double source[5] = {1.1, 2.2, 3.3., 4.4, 5.5};
double target [5];
copy_arr(source, target, 5);
display_array(target, 5);
sort(target, 5);
display_array(source, 5);//for comparing
display_array(target, 5);
}

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2021-11-03 22:02
    关注
    #include <stdio.h>
    void copy_arr(double *source,double *target,int n)
    {
          for(int i=0;i<n;i++)
              *(target+i) = *(source+i);
    }
    
    void sort(double *arr,int n)
    {
          int i,j;
          double d;
          for(i=0;i<n-1;i++)
              for(j=0;j<n-i-1;j++)
              {
                    if(arr[j] < arr[j+1])
                    {
                          d = arr[j];
                          arr[j]= arr[j+1];
                          arr[j+1] = d;
                    }
              }
    }
    
    void display_array(double *arr,int n)
    {
          for(int i=0;i<n;i++)
              printf("%lf ",arr[i]);
    }
    
    int main(){
    double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
    double target [5];
    copy_arr(source, target, 5);
    display_array(target, 5);
    sort(target, 5);
    display_array(source, 5);//for comparing
    display_array(target, 5);
    }
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月17日
  • 已采纳回答 11月17日
  • 创建了问题 11月3日

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗