Advertisement
apl-mhd

Missing element

Aug 4th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include<cstdio>
  2.  
  3.  
  4. int solution(int A[], int N);
  5.  
  6. int main(){
  7.  
  8. int number [] = {1,2,5,3};
  9.  
  10. solution(number, 4);
  11.  
  12.  
  13.  
  14. return 0;
  15. }
  16.  
  17.  
  18. int solution(int A[], int N){
  19.  
  20.  
  21. int i, j, temp;
  22.  
  23. for(i = 0; i < N; i++){
  24.  
  25. for( j = 0; j < N-1; j++){
  26.  
  27. if(A[j] < A[j+1]){
  28.  
  29. temp = A[j];
  30. A[j] = A[j+1];
  31. A[j+1] = temp;
  32. }
  33.  
  34.  
  35. }
  36. }
  37.  
  38.  
  39. for(i = 0; i < N; i++){
  40.  
  41.  
  42.  
  43.  
  44. printf("A[%d] = %d\n", i, A[i]);
  45.  
  46.  
  47.  
  48. }
  49.  
  50. for(i = 0; i < N-1; i++){
  51.  
  52. if(A[i] - A[i+1] == 2 ){
  53.  
  54.  
  55. printf("%d\n", A[i]-1);
  56.  
  57. break;
  58.  
  59. }
  60.  
  61. // printf("%d\n", A[i]);
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement