Home > Back-end >  /C language help kindergarten calculator (1 digits plus or minus)
/C language help kindergarten calculator (1 digits plus or minus)

Time:03-23

To post the results (I can't send pictures, hand make command window)

Please enter in the number of figures:
Please enter the formula:
1-1 + 1
N [0]=1 n 1 n [4] [2]==1 result0=1
N [1]=3 n [2] - [3]=0 n=1 n [4] [5]=0=1 n result=2

Is 1 to 1 + 1=2

?????



#include
#include
#include
Void main ()
{

{
Printf (" hw additional \ n ");
Int I, j=0, result, sz.
Printf (" please enter in the number of figures: \ n ");
The scanf (" % d ", & amp; Sz);/* number, sz is calculated digital control loop condition, to prevent the occurrence of excess behind strange items */
getchar();//absorb enter
Printf (" please enter formula: \ n ");
Char a [2] * sz - 1, n) [2] * sz - 1, TMP.
Gets (a);
//this is a character can be converted to an integer
for(int i=0; i<2 * sz - 1; I++)
{
If (a [I]!='\ n')//meet enter end, however, there is no use
{
If (a [I] <='9' & amp; & A [I] & gt;='0')
{

N=a [I] - [I] '0'.
Printf (" n [% d]=% d ", I, n [I]);

}
}
The else break;

}
Result=n [0];
//printf (" result0=% d ", result);
//this is calculated and subtract
for(i=0; i<2 * sz - 1; I++)
{


If (a [I]! )
='\ n'{

If (a [I]='45')//minus the ASCII 45
{
Printf (" n [% d]=% d ", I + 1, n + 1] [I);
The result -=n + 1] [I;
}
Else if (a=[I] '43')//plus
{
The result +=n + 1] [I;
}
}
The else break;



}
Printf (" result=% d ", result);

}


Trouble for help to see

CodePudding user response:

Reference:
 # include & lt; Stdio. H> 
#include
#include
Void main ()
{

//{//here is much more '{
'Printf (" hw additional \ n ");
Int I, j=0, result, sz.
Printf (" please enter in the number of figures: \ n ");
The scanf (" % d ", & amp; Sz);/* number, sz is calculated digital control loop condition, to prevent the occurrence of excess behind strange items */
getchar();//absorb enter
Printf (" please enter formula: \ n ");
Char * a=new char [2] * sz - 1, * n=new char [2] * sz - 1, TMP.//char a [2] * sz - 1, n) [2] * sz - 1, TMP.
Gets (a);//dynamic char []
//this is a character can be converted to an integer
for(int i=0; i<2 * sz - 1; I++)
{
If (a [I]!='\ n')//meet enter end, however, there is no use
{
If (a [I] <='9' & amp; & A [I] & gt;='0')
{

N=a [I] - [I] '0'.
Printf (" n [% d]=% d ", I, n [I]);

}
}
The else break;

}
Result=n [0];
//printf (" result0=% d ", result);
//this is calculated and subtract
for(i=0; i<2 * sz - 1; I++)
{


If (a [I]! )
='\ n'{

If (a [I]=='-')//if (a=[I] '45')//this is'=='//minus ASCII to 45
{
Printf (" n [% d]=% d ", I + 1, n + 1] [I);
The result -=n + 1] [I;
}
Else if (a [I]=='+')//else if (a=[I] '43') is'=='/plus
{
The result +=n + 1] [I;
}
}
The else break;
}
Printf (" result=% d ", result);
The delete [] a; The delete [] n.

}

CodePudding user response:

Fast by the crazy, although this is the most simple calculator
  • Related