帮我编以下的程序

来源:百度知道 编辑:UC知道 时间:2024/06/05 21:02:39
if-else if语句的用法。编写一个能够进行加减法运算的程序,要求:从键盘任意输入两个实数,然后输入一个运算符,当运算符为“+”时对两个数进行加法运算,为“-”时对两个数进行减法运算,其他符号时,只显示输入的符号不进行运算。
运行以上程序,并写出运行结果。

#include <stdio.h>

void main()
{
float a, b;
scanf("%f%f", &a, &b);
char c;
while (1)
{
c = getchar();
if (c != '\n' && c != ' ' && c != '\t')
break;
}
if (c == '+')
printf("%f + %f = %f", a, b, a + b);
else
if (c == '-')
printf("%f - %f = %f", a, b, a - b);
else
printf("%f %c %f", a, c, b);
printf("\n");
}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b;
string myOperator = string.Empty;
Console.WriteLine("请输入第一个数:\r\n");
a = int.Parse(Console.ReadLine());