Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1667 connectés 

  FORUM HardWare.fr
  Programmation

  C/C++ : fct de recherche de max ds tableau ???

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

C/C++ : fct de recherche de max ds tableau ???

n°14246
HelloWorld
Salut tout le monde!
Posté le 14-02-2001 à 11:27:59  profilanswer
 

C'est encore moi ... ;-)
Est-ce qu'il y a une bibliotheque qui contient des fct toutes faites de recherche de max,min moyenne dans des tableaux ??? genre stdio.h pour la sortie écran ....thx

mood
Publicité
Posté le 14-02-2001 à 11:27:59  profilanswer
 

n°14247
Toxin
Carpe ★★ Vitam
Posté le 14-02-2001 à 11:36:41  profilanswer
 

En standard C je ne pense pas.


---------------
"If you can walk away from a landing, it's a good landing. If you use the airplane the next day, it's an outstanding landing." - Chuck Yeager. | Chaîne YT | Photos
n°14369
Feanor
Hébéphrène à temps partiel
Posté le 14-02-2001 à 18:05:17  profilanswer
 

ben disons que c'est la première chose qu'on apprend à faire sur les tableaux et que ca se fait en 1 min et que y a pas de méthode méga efficace pour ça...
 
alors pourquoi faire une telle fonction.....

n°14402
la viper
Posté le 14-02-2001 à 21:19:37  profilanswer
 

void max(int *ptr,int length)
{

n°14403
la viper
Posté le 14-02-2001 à 21:21:38  profilanswer
 

int max(int *ptr,int length)
{
 int max = 0;
 for(int i=0;i<length;i++)
 {
    if (ptr[i]>max) max = ptr[i];
 }
 return max;
}

n°14460
Toxin
Carpe ★★ Vitam
Posté le 15-02-2001 à 09:55:04  profilanswer
 

Et si le tableau ne contient que des nombres négatifs ?
Il faut initialiser max à ptr[0] et boucler de 1 à lenght.


---------------
"If you can walk away from a landing, it's a good landing. If you use the airplane the next day, it's an outstanding landing." - Chuck Yeager. | Chaîne YT | Photos
n°14464
gilou
Modérateur
Modzilla
Posté le 15-02-2001 à 10:44:22  profilanswer
 

Un truc comme ca, quoi:
 
int max(int *ptr,int length)  
{  
int max;
 
if (lenght<= 0)
  exit(-1); /* quittons le prog */
 
max = ptr[0];  
for(int i=1;i<length;i++)  
{  
    if (ptr[i]>max) max = ptr[i];  
}  
return max;  
}


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°14466
Toxin
Carpe ★★ Vitam
Posté le 15-02-2001 à 10:53:13  profilanswer
 

Y'a pas à dire vive les exceptions du C++ pour gérer des cas pareils (exit (-1)).


---------------
"If you can walk away from a landing, it's a good landing. If you use the airplane the next day, it's an outstanding landing." - Chuck Yeager. | Chaîne YT | Photos

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  C/C++ : fct de recherche de max ds tableau ???

 

Sujets relatifs
[VC++ 6.0 MFC] tres urgent, je recherche une classe sur les sockets[JAVA ou JAVASCRIPT] Où trouver un moteur de recherche pour site ?
Recherche script php pour moteur de recherche dans une base MySQLConversion tableau -> tableau en HTML ou VBScript
[ASP / VBscript] Tableau à n dimensionsRecherche de toute URGENCE : socket.h , netdb.h , in.h et inet.h !!!!!
[Visual C++] Recherche sites intéressants[html] balise méta pour moteurs de recherche
[VB6] les guillemets dans une recherche ... avec SQLRecherche librairie C++ pour traitement d'image HELP
Plus de sujets relatifs à : C/C++ : fct de recherche de max ds tableau ???


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR