finding sum,min,max with array

后端 未结 6 1438
北恋
北恋 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:35

    Try this...

    #include 
    
    int main(void)
    
        {   
            float temp;
            int val,i,j,k;
            double sum = 0;
            double max,min;
    
    
            printf("Enter the number of values: ");
            scanf("%d", &val);
            double number[val];
    
            for(i=0; i < val ;i++)
            { 
                printf("enter a value: ");
                scanf("%lf", &number[i]);
                sum = sum + number[i];
            }
    
            min = number[0];
            max = number[0];
    
            for(j=0;j max)
                max = number[k];
            }
    
            printf("Sum = %.lf\n", sum);
    
            printf ("Maximum element: %.f\n",max);  
    
                printf ("Minimum element: %.lf\n",min);  
    
        }
    

提交回复
热议问题