Guest User

KtraDayTang_dsL_FamiHug

a guest
Nov 23rd, 2010
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. //by FamiHug
  4. int main()
  5. {
  6.     typedef struct ds
  7.     {
  8.         int info;
  9.         struct ds *link;
  10.     } dslk;
  11.     int n,i,cntr=0;
  12.     dslk *p,*l,*t;//l la contro co dinh tro den phan tu dau tien.t la con tro temp
  13.     t=NULL;
  14.    
  15.     printf("CHUONG TRINH KIEM TRA DAY NHAP VAO CO TANG KHONG\n");
  16.     printf("Nhap vao so phan tu cua day: ");
  17.     scanf("%d",&n);
  18. if(n>=2)
  19.     {
  20.     for(i=1;i<=n;i++)
  21.     {
  22.         p=(dslk *)malloc(sizeof(dslk));
  23.         if(t==NULL)
  24.         {
  25.             p->link=NULL;
  26.             t=p;
  27.         }
  28.         if(i==1) l=p;
  29.         else
  30.         {
  31.             p->link=t;
  32.             t=p;
  33.         }
  34.     }
  35.    
  36.     l=p;
  37.     for(i=1;i<=n;i++)//Nhap tu dau den cuoi ds
  38.     {
  39.         printf("Phan tu thu %d la ",i);
  40.         scanf("%d",&p->info);
  41.         p=p->link;
  42.     }
  43.    
  44. //Kiem tra tang
  45.  
  46.     p=l;
  47.     for(i=1;i<=n-1;i++)
  48.     {      
  49.         if(p->info<p->link->info)
  50.         {
  51.             cntr++;
  52.         }
  53.        p=p->link;
  54.      }
  55.        
  56.         if(cntr==n-1)
  57.         printf("Day vua nhap la day tang");
  58.         else
  59.         printf("Day vua nhap KHONG la day tang");
  60. }
  61. else
  62. printf("So nhap vao khong hop le. Chuong trinh ket thuc");
  63.  
  64.     return 1;}
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×