begin process at 2012 02 12 23:57:32
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > QUELQUES FONCTIONS SUR DES TABLEAUX !

QUELQUES FONCTIONS SUR DES TABLEAUX !


 Information sur la source

Note :
Aucune note
Catégorie :Divers Niveau :Débutant Date de création :10/06/2003 Date de mise à jour :10/06/2003 16:14:15 Vu :5 901

Auteur : JCDjcd

Ecrire un message privé
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


 Description

Calcul du minimum, maximum et de la somme d'un tableau !

Source

  • #include <stdio.h>
  • #include <conio.h>
  • // la taille d'un tableau
  • #define SIZE_TAB(tab) (sizeof((tab))/sizeof(((tab)[0])))
  • // affiche un tableau
  • void PrintTab(int *tab,int nbElem)
  • {
  • printf("{%d",*tab);
  • while(--nbElem)
  • printf(",%d",*(++tab));
  • printf("}");
  • }
  • // le minimun d'un tableau
  • int MinTab(int *tab,int nbElem)
  • {
  • int curMin = *tab;
  • while(--nbElem)
  • if(*(++tab) < curMin)
  • curMin = *tab;
  • return curMin;
  • }
  • // le maximun d'un tableau
  • int MaxTab(int *tab,int nbElem)
  • {
  • int curMax = *tab;
  • while(--nbElem)
  • if(*(++tab) > curMax)
  • curMax = *tab;
  • return curMax;
  • }
  • // fait la somme de tous les elements
  • int SumTab(int *tab,int nbElem)
  • {
  • int s = *tab;
  • while(--nbElem)
  • s += *(++tab);
  • return s;
  • }
  • // ============== MAIN ==============
  • int main(int argc,char **argv)
  • {
  • int tab[] = {1,9,-5,54,-100};
  • int size;
  • int min,max,sum;
  • // initialisation :
  • size = SIZE_TAB(tab);
  • // calculs :
  • min = MinTab(tab,size);
  • max = MaxTab(tab,size);
  • sum = SumTab(tab,size);
  • // affichage :
  • printf("Voici un tableau : ");
  • PrintTab(tab,size); // on affiche le tableau
  • printf("\n"); // on saute une ligne
  • printf("Son minimum est %4d.\n",min);
  • printf("Son maximun est %4d.\n",max);
  • printf("Sa somme est %4d.\n",sum);
  • // on attend la frappe d'une touche :
  • getch();
  • return 0;
  • }
#include <stdio.h>
#include <conio.h>

// la taille d'un tableau
#define SIZE_TAB(tab) (sizeof((tab))/sizeof(((tab)[0])))
// affiche un tableau
void PrintTab(int *tab,int nbElem)
{
printf("{%d",*tab);
while(--nbElem)
  printf(",%d",*(++tab));
printf("}");
}
// le minimun d'un tableau
int MinTab(int *tab,int nbElem)
{
int curMin = *tab;
while(--nbElem)
  if(*(++tab) < curMin)
    curMin = *tab;
return curMin;
}
// le maximun d'un tableau
int MaxTab(int *tab,int nbElem)
{
int curMax = *tab;
while(--nbElem)
  if(*(++tab) > curMax)
    curMax = *tab;
return curMax;
}
// fait la somme de tous les elements
int SumTab(int *tab,int nbElem)
{
int s = *tab;
while(--nbElem)
  s += *(++tab);
return s;
}
// ============== MAIN ==============
int main(int argc,char **argv)
{
int  tab[] = {1,9,-5,54,-100};
int       size;
int       min,max,sum;

// initialisation :
size = SIZE_TAB(tab);
// calculs :
min = MinTab(tab,size);
max = MaxTab(tab,size);
sum = SumTab(tab,size);
// affichage :
printf("Voici un tableau : ");
PrintTab(tab,size); // on affiche le tableau
printf("\n");       // on saute une ligne
printf("Son minimum est %4d.\n",min);
printf("Son maximun est %4d.\n",max);
printf("Sa somme est    %4d.\n",sum);
// on attend la frappe d'une touche :
getch();
return 0;
}



 Sources du même auteur

Source avec Zip Source avec une capture COLORATION SYNTAXIQUE
Source avec Zip Source avec une capture ORBITES DES SATELLITES GPS
Source avec Zip Source avec une capture DESSIN D'ARBRES
Source avec Zip Source avec une capture PROGRAMMATION LINEAIRE
Source avec Zip EXTENSION DE CORPS (MATH)

 Sources de la même categorie

Source avec Zip ÉDITEUR DE RECTANGLES EN CONSOLE par seoseo
CONVERSION DE FICHIER EN FICHIER BMP par seoseo
Source avec Zip DETECTEUR EJP par idpro
Source avec Zip Source avec une capture SHOP MANAGER CONSOLE SUR WINDOWS par antho974
Source avec Zip JOUR DE NAISSANCE par fredg19

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales