Advertisement
Guest User

The is Connected

a guest
Dec 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int n,r,n1,n2;
  6. int ar[100][100];
  7.  
  8. printf("Enter N : ");
  9. scanf("%d",&n);
  10.  
  11. printf("Enter R : ");
  12. scanf("%d",&r);
  13.  
  14. printf("Enter n1: ");
  15. scanf("%d",&n1);
  16.  
  17. printf("Enter n2: ");
  18. scanf("%d",&n2);
  19.  
  20. int i,j;
  21.  
  22. int num=0;
  23. for(i=0; i<n; i++)
  24. {
  25. for(j=0; j<n; j++)
  26. {
  27. ar[i][j]=num+1;
  28. num++;
  29. }
  30. }
  31.  
  32. printf("\n");
  33.  
  34. for(i=0; i<n; i++)
  35. {
  36. for(j=0; j<n; j++)
  37. {
  38. printf("%d\t",ar[i][j]);
  39. }
  40. printf("\n");
  41. }
  42.  
  43. int a,b;
  44.  
  45. for(i=0; i<n; i++)
  46. {
  47. for(j=0; j<n; j++)
  48. {
  49. if(n1==ar[i][j])
  50. {
  51. a=i;
  52. b=j;
  53. break;
  54. }
  55. }
  56. }
  57.  
  58. int isConnected = 0;
  59.  
  60. for(i=a-r; i<=a+r; i++)
  61. {
  62. if(i>=0 && i<n)
  63. {
  64. for(j=b-r; j<=b+r; j++)
  65. {
  66. if(j>=0 && j<n)
  67. {
  68. if(ar[i][j]==n2)
  69. {
  70. isConnected = 1;
  71. }
  72. }
  73.  
  74. }
  75.  
  76. }
  77.  
  78. }
  79.  
  80. if(isConnected==1)
  81. {
  82. printf("\nConnected!!\n");
  83. }
  84. else
  85. {
  86. printf("\nNot Connected!!\n");
  87. }
  88.  
  89. return 0;
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement