vuoi
o PayPal
tutte le volte che vuoi
C++ - Conversione da decimale ad esadecimale
Codice C++ del programma:
//Programma che converte un numero decimale in un numero esadecimale.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int num;
int n=0;
char resti[n];
int resto;
cout<<"Inserisci il numero decimale."<<endl;
cin>>num;
while (num>0)
{
resto=num%16;
switch (resto)
{
case 0:
resti[n]='0';
break;
case 1:
resti[n]='1';
break;
case 2:
resti[n]='2';
break;
case 3:
resti[n]='3';
break;
case 4:
resti[n]='4';
break;
case 5:
resti[n]='5';
break;
case 6:
resti[n]='6';
break;
case 7:
resti[n]='7';
break;
case 8:
resti[n]='8';
break;
case 9:
resti[n]='9';
break;
case 10:
resti[n]='A';
break;
case 11:
resti[n]='B';
break;
case 12:
resti[n]='C';
break;
case 13:
resti[n]='D';
break;
case 14:
resti[n]='E';
break;
case 15:
resti[n]='F';
break;
default:
break;
}
num=num/16;
n++;
}
n--;
cout<<"Il numero convertito e':"<<endl;
while (n>=0)
{
cout<<resti[n];
n--;
}
cout<<endl;
return 0;
}
//Programma che converte un numero decimale in un numero esadecimale.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{ int num;
int n=0;
char resti[n];
int resto;
cout<<"Inserisci il numero decimale."<<endl;
cin>>num;
while (num>0)
{ resto=num%16;
switch (resto)
{
case 0:
resti[n]='0';
break;
case 1:
resti[n]='1';
break;
case 2:
resti[n]='2';
break;
case 3:
resti[n]='3';
break;
case 4:
resti[n]='4';
break;
case 5:
resti[n]='5';
break;
case 6:
resti[n]='6';
break;
case 7:
resti[n]='7';
break;
case 8:
resti[n]='8';
break;
case 9:
resti[n]='9';
break;
case 10:
resti[n]='A';
break;
case 11:
resti[n]='B';
break;
case 12:
resti[n]='C';
break;
case 13:
resti[n]='D';
break;
case 14:
resti[n]='E';