Sunteți pe pagina 1din 1

1 //subgraf dintr-un graf¬

2 ¬
3 # include <stdio.h>¬
4 # include <conio.h>¬
5 ¬
6 void main(void){¬
7 int n,a[50][50],i,j,m,v[50],k;¬
8 FILE *f;¬
9 ¬
10 f=fopen("graf.in","r");¬
11 fscanf(f,"%d",&n);¬
12 for(i=1;i<=n;i++)¬
13 for(j=1;j<=n;j++)¬
14 fscanf(f,"%d",&a[i][j]);¬
15 fclose(f);¬
16 printf("\n graful citit are %d noduri!",n);¬
17 printf("\n matricea sa de adiacenta este:\n");¬
18 for(i=1;i<=n;i++){¬
19 for(j=1;j<=n;j++)¬
20 printf("%d ",a[i][j]);¬
21 printf("\n");¬
22 }¬
23 printf("\n cate varfuri doriti sa eliminati?");¬
24 scanf("%d",&m);¬
25 printf("introduceti cele %d varfuri:",m);¬
26 for(i=1;i<=m;i++) scanf("%d",&v[i]);¬
27 for(k=1;k<=m;k++){¬
28 for(i=v[k]-k+1;i<n;i++)¬
29 for(j=1;j<=n;j++)¬
30 a[i][j]=a[i+1][j];¬
31 for(i=1;i<=n;i++)¬
32 for(j=v[k]-k+1;j<n;j++)¬
33 a[i][j]=a[i][j+1];¬
34 n=n-1;¬
35 }¬
36 printf("subgraful rezultat are %d varfuri,matricea sa fiind:\n",n);¬
37 for(i=1;i<=n;i++){¬
38 for(j=1;j<=n;j++)¬
39 printf("%d ",a[i][j]);¬
40 printf("\n");¬
41 }¬
42 getch();¬
43 }¬
44