| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 
 | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
 
typedef struct point point;
struct point
{
 
double x;
double y;
double z;
int *tab1;
};
 
point *tab2;
 
 
 
int main(int argc, char *argv[])
{
int dim,n;
int k,k1,e=0;
 
	printf("Entrez la dimension du tableau tab1\n");
	scanf("%d",&n);
	printf("%d\n",n);
 
	printf("Entrez la dimension du tableau tab2\n");
	scanf("%d",&dim);
	printf("%d\n",dim);
 
 
	/* Allocation dynamique du tableau tab2 */
 
    tab2=calloc(dim,sizeof(struct point));
 
	if(tab2==NULL){printf("Allocation tab2 impossible\n");exit(-1);}
 
	   /* Remplissage du tableau tab2 */
	   for(k=0;k<dim;k++)
	   {
	       tab2[k].x=(double)k+1;
		   tab2[k].y=2.0*(double)k+rand();
		   tab2[k].z=3.0*(double)k+rand();
		   tab2[k].tab1=calloc(n,sizeof(int));
		   if(tab2[k].tab1==NULL){printf("Allocation tab1 impossible\n");e+=1;}
	   }
 
	   /* Affichage du tableau tab2 */
	   k=0;
	   do{
	     printf("%lf %lf %lf \n",tab2[k].x,tab2[k].y,tab2[k].z);
		k++;
	   }while(k<dim);
 
 
 
 
 
	    /* Remplissage de tab1 */
		for(k=0;k<dim;k++){
			for(k1=0;k1<n;k1++)
			{
				tab2[k].tab1[k1]+=1;
			}
		}
 
	    /* Affichage de tab1*/
		for(k=0;k<dim;k++){
			for(k1=0;k1<n;k1++)
			{
				 printf("tab2[%d].tab1[%d]=%d \n",k,k1,tab2[k].tab1[k1]);
			}
			printf("\n");
		}
 
 
	 /* Liberation memoire tableau tab1 */
	 for(k=0;k<dim;k++)
	 {
			if(tab2[k].tab1!=NULL){free(tab2[k].tab1);tab2[k].tab1=NULL;}
	 }
 
    /* Liberation de la memoire allouee au tab2 */	 
	if(tab2!=NULL){free(tab2);}
	tab2=NULL;
 
	return EXIT_SUCCESS;
 
} | 
Partager