Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #define max 1000
  5.  
  6. int sodep(int a)
  7. {
  8.     int i,b[max],c[max],len=0,count1=0,count2=0;
  9.     while (a!=0)//cho cac chu so vao mang b
  10.     {
  11.         b[len]=a%10;
  12.         a/=10;
  13.         len++;
  14.     }
  15.     for (i=0;i<len;i++)
  16.         c[i]=b[i];
  17.     for (i=0;i<len;i++)//dao nguoc lai mang b de so sanh
  18.         b[i]=c[len-i-1];
  19.     for (i=0;i<len-1;i++)//123 thi so sanh tu 1 voi 2, 2 voi 3
  20.     {
  21.         if (b[i+1]==b[i]+1)
  22.             count1++;
  23.         else if (b[i+1]==b[i]-1)
  24.             count1++;
  25.         else //neu ko giam hoac tang dan thi break, return 0
  26.         {
  27.             count2++;
  28.             break;
  29.         }
  30.     }
  31.     if (count2!=0)
  32.         return 0;
  33.     else return 1; 
  34. }
  35. int main()
  36. {
  37.     int n,j,dem=0;
  38.     scanf("%d",&n);
  39.     for (j=pow(10,n-1);j<=pow(10,n);j++)
  40.         if(sodep(j)==1)
  41.             dem++;
  42.     printf("%d",dem);  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement