Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void A(int n3) {
- printf("答案是:");
- printf("%d\n", n3);
- }
- int main(int argc, char *argv[]) {
- int n1 = 0;
- int n2 = 0;
- char c = ' ';
- char clearChar = ' ';
- printf("輸入二個數字:");
- scanf("%d %d", &n1, &n2);
- while ((clearChar = getchar()) != EOF && clearChar != '\n');/* 清空緩衝區 */
- printf("輸入一個符號:");
- scanf("%c", &c);
- int n3 = 0;
- if (c == '+') {
- n3 = n1 + n2;
- }
- else {
- if (c == '-') {
- n3 = n1 - n2;
- }
- else {
- if (c == '*') {
- n3 = n1 * n2;
- }
- else {
- if (c == '/') {
- n3 = n1 / n2;
- }
- else {
- /* do nothing */
- }
- }
- }
- }
- A(n3);
- printf("\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement