Utiliser les pointeurs pour les tableaux
Résolu
yadhus
Messages postés
33
Date d'inscription
Statut
Membre
Dernière intervention
-
dekker Messages postés 371 Date d'inscription Statut Membre Dernière intervention -
dekker Messages postés 371 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai des problèmes pour saisir un tableau et l'afficher à l'aide des pointeurs; Bref voici le code source que j'ai essayé mais ça ne marche pas........
#include <stdio.h>
typedef char * string;
int saisie_tab (int *p, string mess, int N) {
int *pdeb,*pfin;
int T[10];
pdeb=&T[0];
pfin=&T[N];
for (p=pdeb-1;p<pfin-1;p++)
{
puts (mess);
scanf ("%d", *p);
}
return *p;
}
void affiche_tab (int *p, int N) {
int *pdeb,*pfin,T[10];
pdeb=&T[0];
pfin=&T[N];
for (p=pdeb-1;p<pfin-1;p++)
{
printf ("\t%d\t|", p);
}
}
int main () {
int *t;
int N=10;
string mess;
gets (mess);
saisie_tab (t,mess,N);
printf ("Voici votre tableau\n");
affiche_tab (t,N);
return 0;
}
Merci d'avance
J'ai des problèmes pour saisir un tableau et l'afficher à l'aide des pointeurs; Bref voici le code source que j'ai essayé mais ça ne marche pas........
#include <stdio.h>
typedef char * string;
int saisie_tab (int *p, string mess, int N) {
int *pdeb,*pfin;
int T[10];
pdeb=&T[0];
pfin=&T[N];
for (p=pdeb-1;p<pfin-1;p++)
{
puts (mess);
scanf ("%d", *p);
}
return *p;
}
void affiche_tab (int *p, int N) {
int *pdeb,*pfin,T[10];
pdeb=&T[0];
pfin=&T[N];
for (p=pdeb-1;p<pfin-1;p++)
{
printf ("\t%d\t|", p);
}
}
int main () {
int *t;
int N=10;
string mess;
gets (mess);
saisie_tab (t,mess,N);
printf ("Voici votre tableau\n");
affiche_tab (t,N);
return 0;
}
Merci d'avance
A voir également:
- Utiliser les pointeurs pour les tableaux
- Utiliser chromecast - Guide
- Utiliser iphone comme webcam - Guide
- Tableau croisé dynamique pour les nuls - Guide
- Les tableaux word - Guide
- Utiliser tablette comme deuxieme ecran - Guide
2 réponses
tu te galere la vie je pense
atta je reflechie a ton problome ;)
je te rep dans 30 minute ^^
tu a pas forcement besion des pointeur tu peu ressoudre sa avec un compteur ( pour avoir l'indice du tableau que tu passe en refence dans tes fonction " variable globale" )
je te fait un code dans 30 minute ;)
atta je reflechie a ton problome ;)
je te rep dans 30 minute ^^
tu a pas forcement besion des pointeur tu peu ressoudre sa avec un compteur ( pour avoir l'indice du tableau que tu passe en refence dans tes fonction " variable globale" )
je te fait un code dans 30 minute ;)
tien j ai retrouver un de mes TP sur les tableau si tu veut plus d'info , paularch79@hotmail.com je suis en 1er IRIS
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
void random(int tab[], int n)
{
int nb;
srand( time(0));
for (int cpt=0; cpt<n ;cpt++)
{
nb=(rand()%100);
tab[cpt]=nb;
}
}
void afficher(int tab[], int n)
{
for ( int i=0;i<n;i++)
cout<<tab[i]<<" ";
}
void valmanu (int tab[], int n)
{
int a;
for (int indice=0;indice<n;indice++)
{
cout<<"vous avez rentrer "<< indice<<" chiffre"<<endl;
cin>>a;
tab[indice]=a;
}
}
void totaltab (int tab[],int n, int &total)
{
for(int indice=0;indice<n;indice++)
{
total=total+tab[indice];
}
}
void moyentab ( int tab [],int n,int total, float &moyenne )
{
moyenne=(total/(float)10);
}
void valmax (int tab [],int n,int &max)
{
max=tab[0];
for (int indice=0;indice<n;indice++)
{
if ( tab[indice]>max)
max=tab[indice];
}
}
void valmin (int tab [],int n,int &min)
{
min=tab[0];
for (int indice=0;indice<n;indice++)
{
if ( tab[indice]<min)
min=tab[indice];
}
}
int main()
{
const int NB=10;
int tab[NB];
int total=0;
float moyenne;
int max ;
int min;
int choix;
cout<<"tableau aleatoir tapez 1 "<<endl;
cout<<"tableau manuel tapez 2"<<endl;
cout<<"une autre touche pour quitter"<<endl;
cin>> choix;
switch (choix)
{
case 1:
random(tab, NB);
afficher(tab, NB);
cout<<endl;
totaltab (tab, NB ,total );
cout<<"la somme est egale a "<<total<<endl;
moyentab ( tab, NB, total, moyenne );
cout<<"la moyenne est " <<moyenne<<endl ;
valmax ( tab , NB, max);
cout<<"le max est " <<max<<endl;
valmin ( tab , NB, min);
cout <<"le min est " <<min<<endl;
break;
case 2 :
valmanu (tab, NB) ;
afficher(tab, NB);
cout<<endl;
moyentab ( tab, NB, total, moyenne );
cout<<"la moyenne est " <<moyenne<<endl ;
valmax ( tab , NB, max);
cout<<"le max est " <<max<<endl;
valmin ( tab , NB, min);
cout <<"le min est " <<min<<endl;
break;
default: cout<< " quitter " ;
}
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
void random(int tab[], int n)
{
int nb;
srand( time(0));
for (int cpt=0; cpt<n ;cpt++)
{
nb=(rand()%100);
tab[cpt]=nb;
}
}
void afficher(int tab[], int n)
{
for ( int i=0;i<n;i++)
cout<<tab[i]<<" ";
}
void valmanu (int tab[], int n)
{
int a;
for (int indice=0;indice<n;indice++)
{
cout<<"vous avez rentrer "<< indice<<" chiffre"<<endl;
cin>>a;
tab[indice]=a;
}
}
void totaltab (int tab[],int n, int &total)
{
for(int indice=0;indice<n;indice++)
{
total=total+tab[indice];
}
}
void moyentab ( int tab [],int n,int total, float &moyenne )
{
moyenne=(total/(float)10);
}
void valmax (int tab [],int n,int &max)
{
max=tab[0];
for (int indice=0;indice<n;indice++)
{
if ( tab[indice]>max)
max=tab[indice];
}
}
void valmin (int tab [],int n,int &min)
{
min=tab[0];
for (int indice=0;indice<n;indice++)
{
if ( tab[indice]<min)
min=tab[indice];
}
}
int main()
{
const int NB=10;
int tab[NB];
int total=0;
float moyenne;
int max ;
int min;
int choix;
cout<<"tableau aleatoir tapez 1 "<<endl;
cout<<"tableau manuel tapez 2"<<endl;
cout<<"une autre touche pour quitter"<<endl;
cin>> choix;
switch (choix)
{
case 1:
random(tab, NB);
afficher(tab, NB);
cout<<endl;
totaltab (tab, NB ,total );
cout<<"la somme est egale a "<<total<<endl;
moyentab ( tab, NB, total, moyenne );
cout<<"la moyenne est " <<moyenne<<endl ;
valmax ( tab , NB, max);
cout<<"le max est " <<max<<endl;
valmin ( tab , NB, min);
cout <<"le min est " <<min<<endl;
break;
case 2 :
valmanu (tab, NB) ;
afficher(tab, NB);
cout<<endl;
moyentab ( tab, NB, total, moyenne );
cout<<"la moyenne est " <<moyenne<<endl ;
valmax ( tab , NB, max);
cout<<"le max est " <<max<<endl;
valmin ( tab , NB, min);
cout <<"le min est " <<min<<endl;
break;
default: cout<< " quitter " ;
}