两数相加
#include<stdio.h>
int main()
{
int firstNumber, secondNumber, sumofTwoNumbers;
printf_s("请输入两个整数");
scanf_s("%d %d", &firstNumber, &secondNumber);
sumofTwoNumbers = firstNumber + secondNumber;
printf_s("%d+%d=%d", firstNumber, secondNumber, sumofTwoNumbers);
scanf_s("");
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
这样写没问题,加了char类型出错,存在C++ Stack around the variable 'Operatorstr' was corrupted
#include<stdio.h>
int main()
{
int firstNumber, secondNumber; // 第一个数,第二个数
char Operatorstr; // 运算符
int sumofTwoNumbers; // 和
int differenceofTwoNumbers; // 差
int productofTwoNumbers; // 乘积
int quotient, remainder; // 商,余数
printf_s("2 2 \n");
scanf_s("%d %d", &firstNumber, &secondNumber);
printf_s("+-*/ ");
scanf_s("%s", &Operatorstr,4);
switch (Operatorstr) {
case '+':
sumofTwoNumbers = firstNumber + secondNumber;
printf_s("%d + %d=%d\n", firstNumber, secondNumber, sumofTwoNumbers);
break;
case '-':
differenceofTwoNumbers = firstNumber - secondNumber;
printf_s("%d - %d=%d\n", firstNumber, secondNumber, differenceofTwoNumbers);
break;
case '*':
productofTwoNumbers = firstNumber * secondNumber;
printf_s("%d * %d=%d\n", firstNumber, secondNumber, productofTwoNumbers);
break;
case '/':
quotient = firstNumber / secondNumber;
remainder = firstNumber % secondNumber;
printf_s("%d / %d=%d······%d\n", firstNumber, secondNumber, quotient, remainder);
break;
default:
printf_s("default");
}
scanf_s("");
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
作者:꧁执笔小白꧂