Find the index of maximum and minimum number form a floating-point Array

#include<stdio.h>

int main() {

int size;
int i;

printf("Enter size of the array: ");
scanf("%d", &size);


float vet[size];

for(i = 0; i < size; i++){
      scanf("%f", &vet[i]);
   }
 
   
int  max, min;
max = vet[0];
min = vet[0];
int k = 0;
int l = 0;

    for(i=1; i<size; i++)
    {
  
        if(vet[i] > max)
        {
            max = vet[i];
            k = i ;
        }

      
        if(vet[i] < min)
        {
            min = vet[i];
            l = i;
        }
    }


printf("\nMaximum element index = %d\n", k+1);
printf("\nMinimum element index = %d\n", l+1); 
   
  
return 0;
 }
 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.