Advertisement
LuongIT

so_mang_con_giam_dan

Jan 14th, 2016
3,546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Luong UIT K10
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5. void InputArray(int *n, int a[])
  6. {
  7.     int i;
  8.     printf("Nhap so phan tu: ");
  9.     scanf("%d", &*n);
  10.  
  11.     for (i = 0; i < (*n); i++)
  12.         scanf("%d", &a[i]);
  13. }
  14. int ArrangeArray(int n, int a[])
  15. {
  16.     int i, dem = 0;
  17.  
  18.     if (a[n - 2] > a[n - 1])
  19.         dem++;  //neu phan tu a[n-2]>a[n-1] tuc la no dang giam => dem +1
  20.  
  21.     for (i = 0; i < n; i++)
  22.         if (a[i] > a[i + 1])
  23.             if (a[i + 1] < a[i + 2])
  24.                 dem++;
  25.     return dem;
  26. }
  27. int main()
  28. {
  29.     int n, a[100];
  30.     InputArray(&n, a);
  31.     printf("So mang con giam dan: %d\n", ArrangeArray(n, a));
  32.     getch();
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement