Average, max, and min program in C

前端 未结 8 686
梦毁少年i
梦毁少年i 2021-01-21 02:55

So I\'m coding in C, and I need to come up with code that will take n numbers from the user, and find their minimum, maximum, average, and sum of squares for for their values. S

8条回答
  •  余生分开走
    2021-01-21 02:57

    Enter the first num outside the loop and assign that to max min

    scanf("%d",&num);
    max = min = num;  
    

    Change your while loop to infinite loop

    while(1) {...} 
    

    and now check for the condition that whether your counter count is equal to n is or not to break out from the infinite loop

    if(count == n)
        break;  
    

    Full code after modification:

    #include
    int main()
    {
        float average;
        int i, n, count=0, sum=0, squaresum=0, num, min, max;
    
        printf("Please enter the number of numbers you wish to evaluate\n");
        scanf_s("%d",&n);
    
       printf("Please enter %d numbers\n",n);
    
       scanf_s("%d",&num);
       max = min = num;
    
       while(1)
       {
            if(num>max)
               max=num;
            if(num

提交回复
热议问题