Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 100
  3.  
  4. int S[100], T, i, n;
  5.  
  6. int empty();
  7. void push(int a);
  8. int full();
  9. int pop();
  10.  
  11. int empty()
  12. {
  13.     if(T<=0) return 1;
  14.     else return 0;
  15. }
  16.  
  17. int full()
  18. {
  19.     if(T>=MAX) return 1;
  20.     else return 0;
  21. }
  22.  
  23. int pop()
  24. {
  25.     if(empty()==0)
  26.     {
  27.         T--;
  28.         return S[T];
  29.     }
  30.     else return 0;
  31. }
  32.  
  33. void push(int a)
  34. {
  35.     if(full()==0)
  36.     {
  37.         S[T]=a;
  38.         T++;
  39.     }
  40. }
  41.  
  42. void main()
  43. {
  44.     T=0;
  45.     int x, c, a;
  46.     printf("\n Nhap vao so phan tu cua day ( >= 3): ");
  47.     scanf("%d",&n);
  48.     if(n<3) printf("\n So khong hop le");
  49.     else
  50.     {
  51.     for(i=1;i<=n;i++)
  52.     {
  53.         printf("\n Nhap so thu %d: ", i);
  54.         scanf("%d", &a);
  55.         push(a);
  56.        
  57.        
  58.     }
  59.     printf("\n Day vua nhap: ");
  60.     for(i=0;i<n;i++)
  61.     {
  62.         printf("%2d", S[i]);
  63.     }
  64.  
  65.     c=0;
  66.  
  67.     if(empty()==0)
  68.     {
  69.         for(x=n-2;x>=0;x--)
  70.         {
  71.            
  72.             if(S[T-1] == (S[T]+S[T-2])/2)
  73.             {
  74.                 c++;
  75.             }
  76.             T--;
  77.         }
  78.         if(c==n-2) printf("\n Day tren la cap so cong");
  79.         else printf("\n Day tren khong phai la 1 cap so cong");
  80.     }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement