Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Sazid Nur Ratul
- #include<stdio.h>
- #include<math.h>
- #include<string.h>
- char ch[100], str[100];
- void display()
- {
- int i, j;
- for(i=1; i<=10; i++)
- {
- if(i<=5)
- {
- printf("\n");
- continue;
- }
- for(j=1; j<=60; j++)
- {
- if(j<=50)
- {
- printf(" ");
- continue;
- }
- if(i==8)
- {
- int len=strlen(str), x;
- printf("*");
- len=16-len;
- for(x=1; x<=len; x++)
- {
- printf(" ");
- }
- printf("%s", str);
- for(; x<=len/2; x++)
- {
- printf(" ");
- }
- printf(" *");
- j=60;
- }
- if(i==6)
- printf("* ");
- else if(i==10)
- printf("* ");
- else if(j==51 && i!=8)
- printf("* ");
- else if(j==60 && i!=8)
- printf("* ");
- else
- printf(" ");
- }
- printf("\n");
- }
- }
- int check(int base)
- {
- int high;
- if(base>10)
- {
- high=base-10;
- high+=64;
- }
- int len=strlen(ch);
- if(base<=10)
- {
- for(int i=0; i<len; i++)
- {
- int n=ch[i]-48;
- if(n>=base)
- return 1;
- }
- }
- else
- {
- for(int i=0; i<len; i++)
- {
- if(ch[i]>='0' && ch[i]<='9')
- continue;
- else if(ch[i]>='A' && ch[i]<=high)
- continue;
- return 1;
- }
- }
- return 0;
- }
- int anyToTen(int base)
- {
- int i = 0, ans=0, c;
- int len=strlen(ch);
- for(int j=len-1; j>=0; j--)
- {
- if(ch[j]>='A' && ch[j]<='Z')
- {
- c=ch[j]-64+9;
- }
- else
- {
- c=ch[j]-48;
- }
- ans+=(c*(pow(base, i)));
- i++;
- }
- return ans;
- }
- int tenToAny(int num, int base)
- {
- int cnt=0;
- while(num)
- {
- int c = num%base;
- num/=base;
- if(c>9)
- {
- c-=9;
- str[cnt]=64+c;
- }
- else
- str[cnt]=48+c;
- cnt++;
- }
- strrev(str);
- }
- int stoint()
- {
- int len=strlen(ch);
- int ans=0, c;
- for(int i=0; i<len; i++)
- {
- c=ch[i]-'0';
- ans=(ans*10)+c;
- }
- return ans;
- }
- int main()
- {
- int num, current_base, destination_base, flag=1, ans;
- printf("Enter your current base:");
- while(scanf("%d", ¤t_base)!=EOF)
- {
- printf("Enter your destination base:");
- scanf("%d", &destination_base);
- printf("Enter your number:");
- scanf("%s", ch);
- while(check(current_base))
- {
- printf("You entered wrong based number!\n");
- printf("Enter Again: ");
- scanf("%s", ch);
- }
- if(current_base==destination_base)
- {
- strcpy(str, ch);
- }
- if(current_base==10)
- {
- num=stoint();
- }
- else
- num=anyToTen(current_base);
- tenToAny(num, destination_base);
- display();
- printf("\n\nEnter your current base:");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement