首页 > 代码库 > for循环①护栏长度 ②广场砖面积 ③判断闰年平年

for循环①护栏长度 ②广场砖面积 ③判断闰年平年

 技术分享

 

// static void Main(string[] args)
        {

const double PI = 3.14;       

      const int BAR_UNIT_PRICE = 25;      

       const int BRICK_UNIT_PRICE = 85;      

       //输入        

     int a, b;            

Console.Write("请输入泳池半径:");          

   string s1 = Console.ReadLine();       

      a = Convert.ToInt32(s1);         

    Console.Write("请输入广场半径:");            

string s2 = Console.ReadLine();           

  b = Convert.ToInt32(s2);

            //运算         

    double l = 2 * PI * a;    //求泳池的周长       

      double area1 = PI * a * a;//泳池的面积。   

          double area2 = PI * b * b;//总面积。        

     double area = area2 - area1;//广场面积         

    double barPrice = l * BAR_UNIT_PRICE; //护栏的总造价        

     double brickPrice = area * BRICK_UNIT_PRICE;//广场的造价。

            //输出       

      Console.WriteLine("护栏的长度是" + l + "米,广场砖的总面积是" + area + "平米,总造价为" + (barPrice + brickPrice) + "元");  

    }

    }
}

 

 

 

 //第二题 判断一元二次方程根的情况。    

技术分享技术分享技术分享技术分享

    

static void Main (string[] args)     

    {             int a, b, c;            //输入;             Console.Write("请输入系数a:");       

      a = Convert.ToInt32(Console.ReadLine());        

     Console.Write("请输入系数b:");        

     b = Convert.ToInt32(Console.ReadLine());          

   Console.Write("请输入系数c:");      

       c = Convert.ToInt32(Console.ReadLine());

            //运算输出        

     if (a == 0)         

    {              

   Console.WriteLine("不是一元二次方程");      

       }         

    else         

    {             

    int d = b * b - 4 * a * c;        

         if (d > 0)            

     {                 

    Console.WriteLine("两个不等实根");          

       }               

  else if (d == 0)       

          {                  

   Console.WriteLine("两个相等实根");       

          }                

else                

{                 

    Console.WriteLine("无实根");      

           }          

   }     

    }    

}

}

 

 

//第三题   输入一个年份判断是闰年,还是平年。   

技术分享技术分享

      static void ccc(string[] args)      

   {        

     int year;            

//输入           

  Console.Write("请输入一个年份:");         

    year = Convert.ToInt32(Console.ReadLine());

  //运算            

//能被400整除;或能被4整除,但不能被100整除。        

     if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))         

    {              

   Console.WriteLine("是闰年");        

     }             else         

    {              

   Console.WriteLine("是平年");         

    }       

  }  

   }

}

 

for循环①护栏长度 ②广场砖面积 ③判断闰年平年