Skip to content

Instantly share code, notes, and snippets.

@skhozinova
Last active June 1, 2017 22:27
Show Gist options
  • Save skhozinova/bfb019f4e053444c8492d222ca94b3d8 to your computer and use it in GitHub Desktop.
Save skhozinova/bfb019f4e053444c8492d222ca94b3d8 to your computer and use it in GitHub Desktop.
0 0 0
1 0 0
1 0 1
#include<stdio.h>
#include<locale.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int n,k=0,i=0,j=0,**gr;
char *nov;
setlocale(LC_ALL,"Russian");
FILE *f;
f=fopen("1.txt","r");
printf("Введите размернось графа:\n");
scanf("%d",&n);
printf("Выберите вершину графа:\n");
scanf("%d",&k);
gr=(int**)malloc(n*sizeof(int**));
nov=(char*)malloc(n*sizeof(char*));
for(i=0;i<n;i++)
{
gr[i]=(int*)malloc(n*sizeof(int*));
}
for(i=0;i<n;i++)
{
printf("Введите вершину:\n");
nov[i]=_getch();
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
fscanf(f,"%d",&gr[i][j]);
printf(" ");
}
for(i=0;i<n;i++)
{
printf("%c ",nov[i]);
}
for(i=0;i<n;i++)
{
printf("\n%c ",nov[i]);
for(j=0;j<n;j++)
{
printf("%d ",gr[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(gr[i][j]==1)
{
if((i==k))
printf("\nВершина %c смежна с %d",nov[i],k);
else if(j==k)
printf("\nВершина %c смежна с %d",nov[j],k);
}
}
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment