Home > Back-end >  How to change this small program from recursion to cycle?
How to change this small program from recursion to cycle?

Time:11-12

I use this calculator applet recursive wrote
Request from left to right
But I run from right to left
Turn to
#include
#include
Float fun (char ch [100]);
Int main ()
{
Char ch [100].
Gets (ch);
Printf (" % f ", fun (ch));
return 0;
}
Float fun (char ch [100])
{
Int I=0, i1; Float a; Char ch1 [100].
While ((ch [I] & gt;=48 & amp; & Ch [I] <=58) | | ch [I]=='. ')
i++; I1=I;
A=atof (ch);
If (ch [i1]=='+')
{the for (I=0; i<100 - i1-1; I++)
Ch1 [I]=ch [I + i1 + 1];
Return a + fun (ch1); }
Else if (ch [i1]=='-')
{the for (I=0; i<100 - i1-1; I++)
Ch1 [I]=ch [I + i1 + 1];
Return a - fun (ch1); }
Else if (ch [i1]=='*')
{the for (I=0; i<100 - i1-1; I++)
Ch1 [I]=ch [I + i1 + 1];
Return a * fun (ch1); }
Else if (ch [i1]=='/')
{the for (I=0; i<100 - i1-1; I++)
Ch1 [I]=ch [I + i1 + 1];
Return a/fun (ch1); }
Else if (ch [i1]=='\ 0')
Return a;
}
  • Related