+ 1

perform operations from strings expersions

How can i perform operation from a string such like "2+5*4" and display answer as 22. input: "20+2*2" output 24

26th Nov 2020, 7:46 AM
Sacalivin Obiri
Sacalivin Obiri - avatar
3 Answers
+ 1
Sacalivin Obiri , in JS you can use eval() function.
26th Nov 2020, 8:04 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
In C, as far as I know, there's no function to do that. You have to write your own. edit: check this https://stackoverflow.com/questions/1151127/evaluating-mathematical-expressions
26th Nov 2020, 11:20 AM
Davide
Davide - avatar