fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <stdio.h>
  9.  
  10. // Déclaration de la fonction qui retourne l'indice du minimum
  11. int indice_min(int arr[], int start, int end) {
  12. // Vérification des indices valides
  13. if (start < 0 || end < 0 || start > end) {
  14. printf("Indices invalides.\n");
  15. return -1; // Renvoie -1 en cas d'erreur
  16. }
  17.  
  18. int min_index = start; // On suppose que le minimum est à l'indice start
  19.  
  20. // Parcours du tableau de start à end
  21. for (int i = start + 1; i <= end; i++) {
  22. if (arr[i] < arr[min_index]) {
  23. min_index = i; // Mise à jour de l'indice du minimum
  24. }
  25. }
  26.  
  27. return min_index; // Retour de l'indice où se trouve la valeur minimale
  28. }
  29.  
  30. int main() {
  31. // Exemple de tableau
  32. int arr[] = {5, 3, 8, 1, 4, 9, 2};
  33. int start = 1;
  34. int end = 5;
  35.  
  36. // Appel de la fonction
  37. int min_index = indice_min(arr, start, end);
  38.  
  39. // Affichage du résultat
  40. if (min_index != -1) {
  41. printf("L'indice du minimum entre %d et %d est: %d\n", start, end, min_index);
  42. }
  43.  
  44. return 0;
  45. }
  46.  
  47.  
  48.  
Success #stdin #stdout 0.01s 5284KB
stdin
45
stdout
L'indice du minimum entre 1 et 5 est: 3