finding sum,min,max with array

后端 未结 6 1487
北恋
北恋 2021-01-24 14:24

Write a program that inputs number of values then inputs these values (double type) one by one in a loop and finally outputs their sum, the maximum value and the minimum value.

6条回答
  •  轮回少年
    2021-01-24 14:32

    If you dont know the array dimension before, use dynamic allocation.

    replace

    float nu[];
    
    i=nu[];
    
    printf("Number of values :");
    scanf("%f",&i);
    

    with:

    float *nu=0;
    printf("Number of values :");
    scanf("%f",&i);
    nu=malloc(i*sizeof*nu); if(!nu) fprintf(stderr,"not enough memory"),exit(1);
    ...
    free(nu);
    

提交回复
热议问题