Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. //Sazid Nur Ratul
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<string.h>
  5. char ch[100], str[100];
  6. void display()
  7. {
  8.     int i, j;
  9.     for(i=1; i<=10; i++)
  10.     {
  11.         if(i<=5)
  12.         {
  13.             printf("\n");
  14.             continue;
  15.         }
  16.         for(j=1; j<=60; j++)
  17.         {
  18.             if(j<=50)
  19.             {
  20.                 printf(" ");
  21.                 continue;
  22.             }
  23.             if(i==8)
  24.             {
  25.                 int len=strlen(str), x;
  26.                 printf("*");
  27.                 len=16-len;
  28.                 for(x=1; x<=len; x++)
  29.                 {
  30.                     printf(" ");
  31.                 }
  32.                 printf("%s", str);
  33.  
  34.                 for(; x<=len/2; x++)
  35.                 {
  36.                     printf(" ");
  37.                 }
  38.                 printf(" *");
  39.                 j=60;
  40.             }
  41.             if(i==6)
  42.                 printf("* ");
  43.             else if(i==10)
  44.                 printf("* ");
  45.             else if(j==51 && i!=8)
  46.                 printf("* ");
  47.             else if(j==60  && i!=8)
  48.                 printf("* ");
  49.             else
  50.                 printf("  ");
  51.         }
  52.         printf("\n");
  53.     }
  54. }
  55. int check(int base)
  56. {
  57.     int high;
  58.     if(base>10)
  59.     {
  60.         high=base-10;
  61.         high+=64;
  62.     }
  63.     int len=strlen(ch);
  64.     if(base<=10)
  65.     {
  66.         for(int i=0; i<len; i++)
  67.         {
  68.             int n=ch[i]-48;
  69.             if(n>=base)
  70.                 return 1;
  71.         }
  72.     }
  73.     else
  74.     {
  75.         for(int i=0; i<len; i++)
  76.         {
  77.             if(ch[i]>='0' && ch[i]<='9')
  78.                 continue;
  79.             else if(ch[i]>='A' && ch[i]<=high)
  80.                 continue;
  81.             return 1;
  82.         }
  83.     }
  84.     return 0;
  85. }
  86. int anyToTen(int base)
  87. {
  88.     int i = 0, ans=0, c;
  89.     int len=strlen(ch);
  90.     for(int j=len-1; j>=0; j--)
  91.     {
  92.         if(ch[j]>='A' && ch[j]<='Z')
  93.         {
  94.             c=ch[j]-64+9;
  95.         }
  96.         else
  97.         {
  98.             c=ch[j]-48;
  99.         }
  100.         ans+=(c*(pow(base, i)));
  101.         i++;
  102.     }
  103.     return ans;
  104. }
  105. int tenToAny(int num, int base)
  106. {
  107.     int cnt=0;
  108.     while(num)
  109.     {
  110.         int c = num%base;
  111.         num/=base;
  112.         if(c>9)
  113.         {
  114.             c-=9;
  115.             str[cnt]=64+c;
  116.         }
  117.         else
  118.             str[cnt]=48+c;
  119.         cnt++;
  120.     }
  121.     strrev(str);
  122. }
  123. int stoint()
  124. {
  125.     int len=strlen(ch);
  126.     int ans=0, c;
  127.     for(int i=0; i<len; i++)
  128.     {
  129.         c=ch[i]-'0';
  130.         ans=(ans*10)+c;
  131.     }
  132.     return ans;
  133. }
  134. int main()
  135. {
  136.     int num, current_base, destination_base, flag=1, ans;
  137.     printf("Enter your current base:");
  138.     while(scanf("%d", &current_base)!=EOF)
  139.     {
  140.         printf("Enter your destination base:");
  141.         scanf("%d", &destination_base);
  142.  
  143.         printf("Enter your number:");
  144.         scanf("%s", ch);
  145.         while(check(current_base))
  146.         {
  147.             printf("You entered wrong based number!\n");
  148.             printf("Enter Again: ");
  149.             scanf("%s", ch);
  150.         }
  151.         if(current_base==destination_base)
  152.         {
  153.             strcpy(str, ch);
  154.         }
  155.         if(current_base==10)
  156.         {
  157.             num=stoint();
  158.         }
  159.         else
  160.             num=anyToTen(current_base);
  161.         tenToAny(num, destination_base);
  162.         display();
  163.         printf("\n\nEnter your current base:");
  164.     }
  165.     return 0;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement