بابهت: دروست کردنی بەرنامە بۆ گۆرینی Decimal to hexadecimal,octal,and binary بە ++C
سڵاو بەرێزان....
هەروەک جارانی تر، ئەم جارە بەرنامەیەکی ترتانم بۆ ئامادە کردوون بە ++C، کە هاوشێوە بەرنامەکەی پێشووە ئەوەی کە ژمارەی Decimalی دەگۆری بۆ binary بەڵام لەسەر داواکاری هەندێ بەرێز ئەمجارە بەرنامەکە فراوانتر بووە، ئەم جارەیان Decimal دەگۆرێ بۆ هەرسێ جۆری تر واتا بۆ hexadecimal,octal,and binary
هیوادارم سوودی لێ ببینن. کە ئەمەش کۆدەکەیە:
#include<iostream.h>
void main()
{
int b[16],hh[16],oct[16],oc,d,i=0,ih=0,io=0,dh,x,h,od,j;
cout<<"\t\"Converting Decimal to Binary,HexaDecimal,and Octal\"\n\n"
<<"\nEnter a decimal number to convert it:";
cin>>d;
x=d;
dh=d;
od=d;
if (d>=0)
{
while(d>0)
{
b[i]=d%2;
d=d/2;
i++;
}
while(dh>0)
{
h=dh%16;
dh=dh/16;
hh[ih]=h;
ih++;
}
while(od>0)
{
oc=od%8;
od=od/8;
oct[io]=oc;
io++;
}
if(x!=0)
{
cout<<endl
<<x
<<" in decimal = (";
for(int j=i-1; j>=0; j--)
cout<<b[j];
cout<<") in binary\n";
cout<<endl
<<x
<<" in decimal = (";
for( j=ih-1; j>=0; j--)
{
if (hh[j]==10) cout<<'A';
else if (hh[j]==11) cout<<'B';
else if (hh[j]==12) cout<<'C';
else if (hh[j]==13) cout<<'D';
else if (hh[j]==14) cout<<'E';
else if (hh[j]==15) cout<<'F';
else
cout<<hh[j];
}
cout<<") in Hexadecimal\n";
cout<<endl
<<x
<<" in decimal = (";
for( j=io-1; j>=0; j--)
cout<<oct[j];
cout<<") in Octal\n";
}
else
{ cout<<endl
<<x
<<" in decimal = (";
cout<<"0) in Binary,Hexadecimal,and Octal ";
}
}
else
cout<<"\n\nWrong input.";
}