cs:c_language:calc
Return to Home page
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/c_language/calc?do=diff&rev2%5B0%5D=&rev2%5B1%5D=1551188114&difftype=sidebyside
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | cs:c_language:calc [2024/04/08 22:35] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Calculator ====== | ||
+ | **Concepts: | ||
+ | '' | ||
+ | |||
+ | **Text:**\\ | ||
+ | Realize a C program that: | ||
+ | * By using the '' | ||
+ | * The program receives as input two float numbers (i.e., the // | ||
+ | * The calculator must executed the operation expressed by the // | ||
+ | * Allowed operators are '' | ||
+ | * Finally, the program must signal an error in the case an incorrect operator is inserted by the user. | ||
+ | |||
+ | **Example**: | ||
+ | < | ||
+ | 3+9 | ||
+ | RESULT: 3.000000 + 9.000000 = 12.000000 | ||
+ | |||
+ | 3^9 | ||
+ | ERROR: operator ' | ||
+ | </ | ||
+ | |||
+ | **Solution: | ||
+ | |||
+ | <file C calc.c> | ||
+ | #include < | ||
+ | |||
+ | int main() { | ||
+ | |||
+ | float op1, op2, ris; | ||
+ | char oper; | ||
+ | int operator_is_recognized = 1; | ||
+ | |||
+ | scanf(" | ||
+ | |||
+ | switch(oper) { | ||
+ | case ' | ||
+ | ris = op1 + op2; | ||
+ | break; | ||
+ | case ' | ||
+ | ris = op1 - op2; | ||
+ | break; | ||
+ | case ' | ||
+ | ris = op1 * op2; | ||
+ | break; | ||
+ | case '/': | ||
+ | ris = op1 / op2; | ||
+ | break; | ||
+ | default: | ||
+ | operator_is_recognized = 0; | ||
+ | } | ||
+ | |||
+ | if (operator_is_recognized) | ||
+ | printf(" | ||
+ | else | ||
+ | printf(" | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/c_language/calc?do=diff&rev2%5B0%5D=&rev2%5B1%5D=1551188114&difftype=sidebyside
/web/htdocs/www.skenz.it/home/data/pages/cs/c_language/calc.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1