用数学运算符处理变量

发布于 2012-11-24  39 次阅读


static void Main(string[] args)
{
double firstNumber, secondNumber; //声明两个变量
string userName; //声明变量
Console.WriteLine("Enter your name:"); //输出文字提示“Enter your name:”即:“输入你的名字按回车键结束:”提示用户输入信息
userName = Console.ReadLine(); //把用户输入的信息储存在userName中
Console.WriteLine("Welcome {0}!", userName); //输出:Welcome +用户输入的信息+!
Console.WriteLine("Now give me a number:"); //输出文字提示"Now give me a number:"即,输入一个数字
firstNumber = Convert.ToDouble(Console.ReadLine()); //把Console.ReadLine()得到的字符串类型转换成double类型,并赋给firstName
Console.WriteLine("Now give me another number:");
secondNumber = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The sum of {0} and {1} is {2}.", firstNumber, secondNumber,firstNumber +secondNumber );
Console.WriteLine("The result of subtracting {0} from {1} is {2}.",firstNumber ,secondNumber ,firstNumber -secondNumber );
Console.WriteLine("The product of {0} and {1} is {2}.", firstNumber, secondNumber, firstNumber * secondNumber);
Console.WriteLine("The result of dividing {0} by {1} is {2}.", firstNumber, secondNumber, firstNumber / secondNumber);
Console.WriteLine("The remainder after dividing {0} and {1} is {2}.", firstNumber, secondNumber, firstNumber % secondNumber);
///输出两个数字的加减乘除结果,并使用余数运算符(%)显示除操作的余数。
Console.ReadKey();

}

除非注明,本博客所有内容 由 秒速340 创作,采用 知识共享 署名-非商业性使用-禁止演绎 3.0 未本地化版本 许可协议进行许可。