Guest User

Untitled

a guest
May 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. /*the program was written by Aleksey Tolstykh 321794968*/
  2. #include <stdio.h>
  3. #include <string.h>
  4. #define N 6
  5. #define M 8
  6. #define V 10
  7. #define Z 100
  8. #define H 4
  9. int check_zone(int nums[][M], int x, int y, int num, int *);
  10. int slope_rec(int [][H], int );
  11. int check_sort(int *, int);//Check if array
  12. void reducing(char *);
  13. int slope_rec(int data[][H], int index)
  14. {
  15. int i=0;
  16. if(index<H)
  17. {
  18. for(i=1;index+i<H;i++)
  19. {
  20. if(!(data[index+i][index]<0 && data[index][index+i]>0 && data[index][index] == 0))
  21. {
  22. return 0;
  23. }
  24. }
  25. if(data[index][index]==0)
  26. {
  27. index++;
  28. slope_rec( data, index);
  29. }
  30. else
  31. return 0;
  32. }
  33. else
  34. return 1;
  35. }
  36. int check_sort(int * arr, int size)
  37. {
  38. if(arr[size-2] > arr[size-1])//Recursion
  39. return 0;
  40. if(size >= 2)
  41. {
  42. size--;
  43. check_sort(arr,size);
  44. }
  45. else
  46. return 1;
  47. }
  48. void reducing(char *string)
  49. {
  50. if(*string == '\0')//Recursion
  51. return;
  52. if(*string >= 48 && *string <= 57)
  53. {
  54. printf("%c",*string);
  55. }
  56. string++;
  57. reducing(string);
  58. }
  59. int check_zone(int nums[][M], int x, int y, int num, int *count)
  60. {
  61. if((x<=N) || (y<=M) || (x>=0) || y>=0)
  62. {
  63. nums[x][y]=0;
  64. *count=*count+1;
  65. if (nums[x-1][y-1]==num)
  66. {
  67. check_zone(nums,x-1,y-1,num,count);
  68. }
  69. if(nums[x-1][y]==num)
  70. {
  71. check_zone(nums,x-1,y,num,count);
  72. }
  73. if(nums[x][y-1]==num)
  74. {
  75. check_zone(nums,x,y-1,num,count);
  76. }
  77. if(nums[x+1][y+1]==num)
  78. {
  79. check_zone(nums,x+1,y+1,num,count);
  80. }
  81. if(nums[x+1][y]==num)
  82. {
  83. check_zone(nums,x+1,y,num,count);
  84. }
  85. if(nums[x][y+1]==num)
  86. {
  87. check_zone(nums,x,y+1,num,count);
  88. }
  89. if(nums[x+1][y-1]==num)
  90. {
  91. check_zone(nums,x+1,y-1,num,count);
  92. }
  93. if(nums[x-1][y+1]==num)
  94. {
  95. check_zone(nums,x-1,y+1,num,count);
  96. }
  97. }
  98. return *count;
  99. }
  100. void main()
  101. {
  102. int choose=1,result=0,result2=0,index=0;
  103. int arr[V]={0};//array
  104. int data[H][H]={0};//array
  105. int size=V;
  106. int i=0,k=0,l=0,j=0;
  107. int nums[N][M]= {{4, 3 ,2 ,3 ,1 ,3 ,2 ,1},//array
  108.  
  109. {5, 3, 3, 2, 2, 2, 1, 2},
  110.  
  111. {1 ,1 ,3 ,3, 2, 1, 2, 1},
  112.  
  113. {1 ,3 ,3 ,2 ,4 ,3 ,3 ,2},
  114.  
  115. {5 ,5 ,3 ,4 ,4 ,4 ,3 ,2},
  116.  
  117. {5 ,3 ,4 ,2 ,2 ,2 ,3 ,2}};
  118. int x=0,y=0,num=0;
  119.  
  120. int count=0;
  121. char str[Z];
  122. while(choose!=5)
  123. {
  124. printf("Choose function:\n1-Check sorting\n2-Reducing\n3-Sloping \n4-Check zone\n5-Exit \n");
  125. scanf("%d",&choose);
  126. switch(choose)// Menu's
  127. {
  128. case 1:
  129. printf("Enter array size 10 for check sorting: \n");
  130. for(i=0;i<V;i++)
  131. {
  132. scanf("%d",&arr[i]);
  133. }
  134. printf("\nThe array is:\n");
  135. for(i=0;i<size;i++)
  136. {
  137. printf("%4d",arr[i]);
  138. }
  139. printf("\n");
  140. result=check_sort(arr,size);
  141. if (result==0)
  142. {
  143. printf("The array is NO sorted !\n\n");
  144. }
  145. if (result==1)
  146. {
  147. printf("The array is sorted !\n\n");
  148. }
  149. break;
  150. case 2:
  151. {
  152. printf("Enter string for reducing:\n");
  153. gets(str);
  154. gets(str);
  155. printf("The reduced string is:\n");
  156. reducing(str);
  157. printf("\n");
  158. }
  159. break;
  160. case 3:
  161. printf("Enter array size %d X %d for check slope\n",H,H);
  162. for(k=0;k<H;k++)
  163. {
  164. printf("Enter row %d:\n",k);
  165. for(l=0;l<H;l++)
  166. {
  167. scanf("%d",&data[k][l]);
  168. }
  169. }
  170. printf("The array is:\n");
  171. for(i=0;i<H;i++)
  172. {
  173. for(j=0;j<H;j++)
  174. {
  175. printf("%3d",data[i][j]);
  176. }
  177. printf("\n");
  178. }
  179. result2=slope_rec(data,index);
  180. if (result2==0)
  181. {
  182. printf("The array is NOT slope ! \n");
  183. }
  184. if (result2==1)
  185. {
  186. printf("The array is slope ! \n");
  187. }
  188. break;
  189. case 4:
  190. printf("Enter the coordinates for number\n");
  191.  
  192. scanf("%d%d",&x,&y);
  193.  
  194. printf("The number is %d\n",nums[x][y]);
  195.  
  196. num=nums[x][y];
  197. for(i=x-1;i<=x+1;i++)
  198. {
  199. for(j=y-1;j<=y+1;j++)
  200. {
  201. printf("%3d",nums[i][j]);
  202. }
  203. printf("\n");
  204. }
  205. check_zone(nums,x,y,num,&count);
  206. printf("The size of the zone is : \n");
  207. printf("%d\n",count);
  208. for(i=0;i<N;i++)
  209. {
  210. for(j=0;j<M;j++)
  211. {
  212. printf("%3d",nums[i][j]);
  213. }
  214. printf("\n");
  215. }
  216. break;
  217. case 5:
  218. {
  219. }
  220. break;
  221.  
  222. }
  223. }
  224. }
Add Comment
Please, Sign In to add comment