Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Luong UIT K10
- #include <stdio.h>
- #include <conio.h>
- void InputArray(int *n, int a[])
- {
- int i;
- printf("Nhap so phan tu: ");
- scanf("%d", &*n);
- for (i = 0; i < (*n); i++)
- scanf("%d", &a[i]);
- }
- int ArrangeArray(int n, int a[])
- {
- int i, dem = 0;
- if (a[n - 2] > a[n - 1])
- dem++; //neu phan tu a[n-2]>a[n-1] tuc la no dang giam => dem +1
- for (i = 0; i < n; i++)
- if (a[i] > a[i + 1])
- if (a[i + 1] < a[i + 2])
- dem++;
- return dem;
- }
- int main()
- {
- int n, a[100];
- InputArray(&n, a);
- printf("So mang con giam dan: %d\n", ArrangeArray(n, a));
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement