Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #include <stdio.h>
  2. void swap(int *a,int *b)
  3. {int temp;
  4. temp=*a;
  5. *a=*b;
  6. *b=temp;
  7. }
  8. void klot(int *arr,int size) //1
  9. {int i;
  10. for( i = 0 ; i < size ; i++)
  11. {
  12. scanf("%d",&arr[i]);
  13. }
  14. }
  15. void print(int *arr,int size) //2
  16. {
  17. for(int i = 0 ; i < size ; i++)
  18. {
  19. printf("num in %d is %d \n",i+1,arr[i]);
  20. }
  21. }
  22. int sum(int *arr,int size) //3
  23. {int sum=0;
  24. for(int i = 0 ; i< size ; i++)
  25. {
  26. sum+=arr[i];
  27. }
  28. return sum;
  29. }
  30. void oppositearray(int *a,int*b,int size) //4
  31. {int i;
  32. for(i = 0 ; i < size ; i++)
  33. {
  34. b[i]=a[size-1-i];
  35. }
  36. }
  37. void oppositethisarray(int *a,int size) // 5
  38. {int i;
  39. for(i = 0 ; i <= size/2 ; i++)
  40. {
  41. swap(&a[i],&a[size-i-1]);
  42. }
  43.  
  44. }
  45. void shr(int *a,int size) // 6 *******************
  46. {int savenum=a[0],i;
  47. a[0]=a[size-1];
  48. a[1]=savenum;
  49.  
  50. }
  51. void max(int *a,int size,int *max,int *maxindex) // 7
  52. {int maxnum=a[0],i;
  53. for(i = 1 ; i < size ; i++)
  54. {
  55. if(a[i]>maxnum)
  56. {
  57. maxnum=a[i];
  58. *max=a[i];
  59. *maxindex=i;
  60. }
  61. }
  62. }
  63. int ismemooyan(int *a, int size) //8
  64. {int i;
  65. for(i = 0 ; i <size-1 ; i++)
  66. {
  67. if(a[i]>=a[i+1]) // im yesh evar shelo katan meaevar aba tahzir 0
  68. return 0;
  69. }
  70. return 1;
  71. }
  72. int search(int *a,int size,int num) // 9
  73. {int i;
  74. for(i=0;i<size;i++)
  75. {
  76. if(a[i]==num)
  77. return i;
  78. }
  79. return -1;
  80. }
  81. void buildsum(int*res,int size) // 10
  82. {int i,j,sum=1;
  83. for(i=0;i<size;i++)
  84. {
  85. if(i==0)
  86. res[i]=1;
  87. else
  88. res[i]=sum;
  89. sum+=res[i];
  90. }
  91. }
  92. void meshootaf(int *a,int*b,int sizea,int sizeb) //11
  93. {
  94. for(int i = 0 ; i <sizea; i++)
  95. {
  96. if(search(b,sizeb,a[i])!=-1)
  97. printf("%d exists in both \n" ,a[i]);
  98. }
  99. }
  100. int specialsearch(int *a,int size,int num,int wherenottosearch) // like search but not to search in a specific index
  101. {int i;
  102. for(i=0;i<size;i++)
  103. {
  104. if(a[i]==num && i!=wherenottosearch)
  105. return i;
  106. }
  107. return -1;
  108. }
  109. int difnumbers(int *a,int size) // 12
  110. {int i;
  111. for(i = 0 ; i <size ; i++)
  112. {
  113. if(specialsearch(a,size,a[i],i)!=-1) // if found this number on a different location from where it is
  114. return 0;
  115. }
  116. return 1;
  117. }
  118. int counttimes(int *a,int size ,int num)
  119. {int i,count=0;
  120. for(i=0;i<size;i++)
  121. {
  122. if(a[i]==num)
  123. count++;
  124. }
  125. return count;
  126. }
  127. int firsttimewedontseethatafterthat(int *a,int size,int num,int index)
  128. {int i;
  129. for(i = index+1 ; i < size ; i++)
  130. {
  131. if(a[i]!=num)
  132. {
  133. return i;
  134. }
  135. }
  136. return -1;
  137. }
  138. void tzafoof(int *a,int size) //13
  139. {int i,j,count=counttimes(a,size,0);
  140. for(i=0;i<count;i++)
  141. {
  142. if(firsttimewedontseethatafterthat(a,size,0,i)!=-1)
  143. swap(&(a[search(a,size,0)]),&(a[firsttimewedontseethatafterthat(a,size,0,i)]));
  144. }
  145.  
  146.  
  147.  
  148. }
  149. void main()
  150. {
  151. int a[5];
  152. int b[5];
  153. klot(a,5);
  154. //klot(b,5);
  155.  
  156. //print(a,5);
  157. //printf("sum is %d \n",sum(a,5));
  158. //oppositearray(a,b,5);
  159. //print(b,5);
  160. //oppositethisarray(a,5);
  161. //shr(a,5);
  162.  
  163. //int maxnum,maxindex;
  164. //max(a,5,&maxnum,&maxindex);
  165. //printf("max num is %d max index is %d \n" , maxnum,maxindex);
  166.  
  167. //printf("ans in %d \n",ismemooyan(a,5));
  168.  
  169. //printf("%d\n",search(a,5,-7));
  170.  
  171. //buildsum(b,5);
  172. //print(b,5);
  173.  
  174. //meshootaf(a,b,5,5);
  175. //printf("ans is %d \n",difnumbers(a,5));
  176.  
  177. tzafoof(a,5);
  178.  
  179.  
  180. print(a,5);
  181. scanf("%d");
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement