实现进制转化伪代码

伪代码如下

    Write "Enter the new base"
    Read newBase
    Write "Enter the number to be converted"
    Read decimalNumber
    Set quotient to 1
    WHILE (quotient is not zero)
    Set quotient to decimalNumber DIV newBase
    Set remainder to decimalNumber REM newBase
    Make the remainder the next digit to the left in the answer
    Set decimalNumber to quotient
    Write "The answer is "
    Write answer

c语言代码

  #include <stdio.h>
  int main()
  {
   int x,p;  
   scanf("%d",&x);
   scanf("%d",&p);
   int a[100];  
   int count=0;
   do{
	   a[count++]=x%p;
	   x=x/p;
      }while(x!=0);

    for(int i=count-1;i>=0;i--)
          {
	    printf("%d",a[i]);
          }
   } 

posted on 2022-10-06 20:49  20221305赵月溪  阅读(18)  评论(0)    收藏  举报

导航