int main(void)
{
	int a, b;
	char op;
	float ans;
	scanf_s("%d%c%d",&a,&op,1,&b);

	if (op == '+')
	{
		ans = (float)a + b;
	}
	else if (op == '-')
	{
		ans = (float)a - b;
	}
	else if (op == '*')
	{
		ans = (float)a*b;
	}
	else if (op == '/')
	{
		ans = (float)a / b;
	}



	printf("%.2f",ans);
	return 1;
}

 

这是一个简单的四则运算的程序,里面用到了if else ,用if else 就一定要明白程序执行的流程,当op==‘+’的时候,执行

ans=(float)a+b,执行完这句之后程序流程就到了printf("%.2f",ans)这里了,一定要明白这里,op==‘+’后面的else都不会执行的。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-01-05
  • 2021-05-29
  • 2021-06-02
  • 2021-11-09
猜你喜欢
  • 2021-05-07
  • 2022-12-23
  • 2021-11-29
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案