1 2 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
   |  
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <malloc.h>
 
void main()
{
 
	int nb_sommets;
 
 nb_sommets = 5;     
 
 
/*int matrice_adj[4][4]={
          {1,1,1,1},
	  {1,1,1,1},
   	  {1,1,1,1}, 
          {0,0,0,1}
              };*/
 
 int matrice_adj[5][5]={
        {1,0,1,1,1},
	{0,1,1,0,1},
        {0,1,1,0,0}, 
        {1,1,0,1,1},
	{1,1,0,1,1}
              };
 
	// printf("%d\n", matrice_adj[3][3]);
int z=0; // agir sur S ou z
int i=z;
int j,S;
 
int ok=1;
int compteur=0;
 
while (ok && i<nb_sommets)
{
	for (S=z;S<2;S++) //for (S=0;S<((5/2)-1);S++) 
{
	j=S;
	while (ok && j<=i)
	{
		ok=(matrice_adj[i][j]==1 && matrice_adj[j][i]==1);
		// cout<<"ok="<<ok<<"et i="<<i<<"et j="<<j<<endl;
	if (ok==0)
		{compteur++; //cout<<compteur<<endl;
			for (int k = S; k < i;k++)
				{
					for (int m = S; m < i;m++)
					{
						//if (k!=m)
						{
							{matrice_adj[k][m]=3;
							matrice_adj[m][k]=3;
							}
						}
					}
				}
		}
		j=j+1;
	}
	if (ok)
	{
		i=i+1;
	}
}
}
 
// fonction affichage de la matrice que je devrai enlever
{
	int i,j;
	for (i = 0; i < nb_sommets;i++)
	{
		for (j = 0; j < nb_sommets;j++)
		{
			cout<<matrice_adj[i][j]<<" ";
		}
		cout<<endl;
	}
}
 
 
} | 
Partager