1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication3 7 { 8 class Program 9 { 10 static void Main(string[] args) 11 { 12 //变量的定义 13 int a,b; 14 int sum,dif,pro,quo; 15 //赋值与加、减、乘、除计算公式 16 a = 8; 17 b = 4; 18 sum=a+b; 19 dif=a-b; 20 pro=a*b; 21 quo=a/b; 22 //在cmd中输出结果 23 Console.WriteLine("a={0}", a); 24 Console.WriteLine("b={0}", b); 25 Console.WriteLine("{0}+{1}={2}", a, b, sum); 26 Console.WriteLine("{0}-{1}={2}", a, b, dif); 27 Console.WriteLine("{0}*{1}={2}", a, b, pro); 28 Console.WriteLine("{0}/{1}={2}", a, b, quo); 29 //变量a值的变化 30 a=100; 31 a=a+1; 32 Console.WriteLine(a); 33 34 } 35 } 36 }
运行的结果如下: