disaste0_0 2022-10-07 02:58 采纳率: 81.6%
浏览 206
已结题

printf 出现c6272的问题

运行的结果是错误的

#include <stdio.h>

int main(void)
{
//set a array
double array[] = { 1,-0.3,6,40,17 };
double largest = array[0], smallest = array[0];

//find the largest and smallest value in array 
for (int i = 0; i < 5; i++)
{
    if (array[i] > largest) {
        largest = array[i];
    }
    if (array[i] < smallest) {
        smallest = array[i];
    }
}
    printf("the largest number is %f\n", &largest);
    printf("the smallest number is %f\n", &smallest);

    
    double sum;
    //a formular of addition
    sum = largest + smallest;
    printf("the sum of the largest and smallest is %f\n", &sum);
return 0;

}

在每一行的printf都显示c6272

img

运行后所有的数都是0

img

我想让这个数组中的最大和最小相加的和

展开全部

  • 写回答

3条回答 默认 最新

  • lzl2040 人工智能领域新星创作者 2022-10-07 03:15
    关注

    printf("the largest number is %f\n", &largest);里面的&不要,之后的类似

    #include <stdio.h>
    
    int main(void)
    {
        //set a array
        double array[] = { 1,-0.3,6,40,17 };
        double largest = array[0], smallest = array[0];
        //find the largest and smallest value in array 
        for (int i = 0; i < 5; i++)
        {
            if (array[i] > largest) {
                largest = array[i];
            }
            if (array[i] < smallest) {
                smallest = array[i];
            }
        }
            printf("the largest number is %f\n", largest);
            printf("the smallest number is %f\n", smallest);
            double sum;
            //a formular of addition
            sum = largest + smallest;
            printf("the sum of the largest and smallest is %f\n", sum);
        return 0;
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 10月15日
  • 已采纳回答 10月7日
  • 创建了问题 10月7日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部