Guest User

Untitled

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