SoFunction
Updated on 2025-03-03

Example of converting decimal into any 2-16 digit in c++

Without further ado, just upload the code

#include<>
#include<>
#include<iostream>
using namespace std;
int main()
{
  //Convert decimal to several binary systems>2,<16 =  int num;
  int n;// Between 2-16  int a;
  int i=0;
  cin&gt;&gt;num&gt;&gt;n;
  int s[100];
  if(n&gt;=2&amp;&amp;n&lt;&lt;16)
  {
    while(num!=0)
    {
      a=num%n;
      num=num/n;
      i++;
      s[i]=a;

    }
    for(int j=i;j&gt;=1;j--)
    {
      if(s[j]&gt;=10)
      {
        cout&lt;&lt;s[j]+55;
      }
      else{
      cout&lt;&lt;s[j];
      }
    }
  }
  else{

    cout&lt;&lt;"error"&lt;&lt;endl;
  }
}

The above example of converting c++ decimal to any 2-16-digit number is all the content I share with you. I hope you can give you a reference and I hope you can support me more.