Home > Back-end >  What a great god can help me to write a C this program, didn't learn a freshman
What a great god can help me to write a C this program, didn't learn a freshman

Time:10-31

CodePudding user response:

The debug step through and study well under:

Int SwitchDecOctPow (int nBase, int nY)
{
Int nResult=1;
for (int i=0; i {
NResult *=nBase;
}

Return nResult;
}

Void SwitchDecOct (void)
{
Bool bRun=true;
While (bRun)
{
Printf (" * * * * * * * * * * * * * * * * * * * * * \ r \ n ");
Printf (" hexadecimal conversion system \ r \ n ");
Printf (" 1, octal is converted to a decimal \ r \ n ");
Printf (" 2, converting decimal octal \ r \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * \ r \ n ");
Printf (" please select the serial number 1 or 2: ");

Int nType=0;
If (scanf_s (" % d ", & amp; NType)!=1
| | nType!=1 & amp; & NType!
=2){
Printf (" input error \ r \ n ");
return;
}

Printf (" please input to convert data: ");

Int nNumber=0;
If (scanf_s (" % d ", & amp; NNumber)!=1
| | nNumber & lt; 0)
{
Printf (" input error \ r \ n ");
return;
}

Int nResult=0;
//oct - & gt; Dec
If (nType==1)
{
for(int i=0; NNumber!=0; + + I)
{
Int nBit=nNumber % 10;
NNumber/=10;

If (nBit & gt;=8)
{
Printf (" input error \ r \ n ");
return;
}

//nResult +=nBit * pow (8, I);
NResult +=nBit * SwitchDecOctPow (8, I);
}
}
//dec - & gt; Oct
The else
{
for (int i=0; NNumber!=0; + + I)
{
Int nBit=8 nNumber %;
NNumber/=8;

//nResult +=nBit * pow (10, I);
NResult +=nBit * SwitchDecOctPow (10, I);
}
}

Printf (" convert: % d \ r \ n ", nResult);

Printf (" whether to convert? y/n:");

Char cContinue=0;
Scanf_s (" c "\ n %, & amp; CContinue, sizeof (char));

BRun=false;
If (cContinue=='y')
BRun=true;
Else if (cContinue=='n')
BRun=false;
The else
Printf (" input error \ r \ n ");
}
}
  • Related