Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX 100
- int S[100], T, i, n;
- int empty();
- void push(int a);
- int full();
- int pop();
- int empty()
- {
- if(T<=0) return 1;
- else return 0;
- }
- int full()
- {
- if(T>=MAX) return 1;
- else return 0;
- }
- int pop()
- {
- if(empty()==0)
- {
- T--;
- return S[T];
- }
- else return 0;
- }
- void push(int a)
- {
- if(full()==0)
- {
- S[T]=a;
- T++;
- }
- }
- void main()
- {
- T=0;
- int x, c, a;
- printf("\n Nhap vao so phan tu cua day ( >= 3): ");
- scanf("%d",&n);
- if(n<3) printf("\n So khong hop le");
- else
- {
- for(i=1;i<=n;i++)
- {
- printf("\n Nhap so thu %d: ", i);
- scanf("%d", &a);
- push(a);
- }
- printf("\n Day vua nhap: ");
- for(i=0;i<n;i++)
- {
- printf("%2d", S[i]);
- }
- c=0;
- if(empty()==0)
- {
- for(x=n-2;x>=0;x--)
- {
- if(S[T-1] == (S[T]+S[T-2])/2)
- {
- c++;
- }
- T--;
- }
- if(c==n-2) printf("\n Day tren la cap so cong");
- else printf("\n Day tren khong phai la 1 cap so cong");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement