Help with counting and comparing a variable in FOR in C

1

I hope you can help me with this statement that I got from homework, I can not find the way to do the point to, and with the rest:

-As a result of an experiment, a laboratory obtained 18 values of temperature, all other than zero. A program must be made to enter these values and then determine and report:

a) The highest temperature entered and what was its number of     order during the entrance.

b) Idem for the lowest temperature.

c) The average of negative temperatures. If there were not     negative temperatures indicate it with a poster explanatory.

This is what I get to do:

#include <stdio.h>

int a, i, max, min;
int main( void ) {
  for (i=0;i<18;i++) {
    printf(" Introduzca el valor de temperatura: \n");
    scanf("%d", &a);

    if(i==0){
      max=a;
      min=a;
    }
  }

  return 0;
}
    
asked by Josias99 25.04.2017 в 22:30
source

1 answer

0

It's done at the head but, except for minimal changes, it should work.

#include <stdio.h>

int max = 0, maxIdx; // Máximas.
int min = 0, minIdx; // Mínimas.
int negAcu = 0, negCount = 0; // Negativas.

int main( void ) {
  int curr;

  for( i = 0; i < 18; ++i ) {
    printf(" Introduzca el valor de temperatura: \n");
    scanf( "%d", curr );

    if( curr > max ) {
      max = curr;
      maxIdx = i;
    }

    if( curr < min ) {
      min = curr;
      minIdx = i;
    }

    if( curr < 0 ) {
      negAcu += curr;
      ++negCount;
    }
  }

  printf( "Temperatura máxima: %d; orden: %d\n", max, maxIdx );
  printf( "Temperatura mínima: %d; orden: %d\n", min, minIdx );

  if( negCount ) {
    printf( "Promedio de temperaturas negativas: %d\n", negAcu / negCount );
  } else {
    printf( "SIN temperaturas negativas.\n" );
  }

  return 0;
}
    
answered by 25.04.2017 / 22:42
source