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

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 11: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月16日
  • 已采纳回答 10月8日
  • 创建了问题 10月7日