第一题:
有一个函数:
y = x (x<1)
y = 2x-1 (1<=x<10)
y = 3x-1 (x>=10)
写一程序,输入x,输出y值。
第二题:
有3个整数a、b、c,由键盘输入,输出其中最小的数。
要求:用if语句编写程序。
第三题:
企业发放的奖金根据利润提成。利润I根据或等于10万元的,奖金可提成10%;利润高于10万元,低于20万元(100000<I<=200000)时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%,200000<I<=400000时,低于20万的部分仍按上述办法提成(下同),高于20万元的部分按5%提成;400000<I<=600000时,高于40万的部分按3%提成;600000<I<=1000000时,高于60万的部分按1.5%提成;I>1000000时,超过100万元的部分按1%提成。从键盘输入当月利润I,求应发奖金总数。
要求:用if或switch语句编写程序
第四题:
实现一个简单的四则运算计算器。
要求:参与运算的两个数值和运算的类型均从控制台输入,顺序为:第一个操作数、第二个操作数、运算类型;用switch语句编写程序。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Test4();
}
//第一题
static void Test1()
{
Console.WriteLine("输入X的值:");
double x = double.Parse(Console.ReadLine());
double y = 1;
if (x < 1)
{
Console.WriteLine(y = x);
}
else if (1 <= x && x < 10)
{
Console.WriteLine (y=2*x-1);
}
else if(x>=10)
{
Console.WriteLine (y=3*x-1);
}
Console.WriteLine();
}
//第二题
//Console.WriteLine("请输入整数a:");
//int a = Convert.ToInt32(Console.ReadLine());
//Console.WriteLine("请输入整数b:");
//int b = Convert.ToInt32(Console.ReadLine());
//Console.WriteLine("请输入整数c:");
//int c = Convert.ToInt32(Console.ReadLine());
//if (a >b&&a>c)
//{
// Console.WriteLine("最小值是" + c);
//}
//else if (b > c&&b>a)
//{
// Console.WriteLine("最小值是" + a);
//}
//else if (c > a&&c>b)
//{
// Console.WriteLine("最小值是" + b);
//}
//第三题switch
//static void Test2()
// {
//Console .WriteLine ("请输入利润:");
// int x=int .Parse(Console.ReadLine ());
// int y = (x / 100000);
// switch(x)
// {
// case 0:
// Console.WriteLine (100000*0.1);
// break;
// case 1:
// Console.WriteLine (100000*0.1+(x-100000)*0.075);
// break ;
// case 2:
// Console.WriteLine (100000*0.1+100000*0.075+(x-200000)*0.05);
// break ;
// case 4:
// Console.WriteLine (100000*0.1+100000*0.075+(x-200000)*0.05);
// break ;
// case 5:
// Console.WriteLine (100000*0.1+100000*0.075+200000*0.05+(x-400000)*0.03);
// break ;
// case 6:
// Console.WriteLine (100000*0.1+100000*0.075+200000*0.05+(x-400000)*0.03);
// break ;
// case 7:
// Console.WriteLine (100000*0.1+100000*0.075+200000*0.05+400000*0.03+(x-600000)*0.015);
// break ;
// case 8:
// Console.WriteLine (100000*0.1+100000*0.075+200000*0.05+400000*0.03+(x-600000)*0.015);
// break ;
// case 9:
// Console.WriteLine (100000*0.1+100000*0.075+200000*0.05+400000*0.03+(x-600000)*0.015);
// break ;
// //case 10:
// // Console.WriteLine (100000*0.1+100000*0.075+200000*0.05+400000*0.03+600000*0.015+(x-1000000)*0.01);
// // break ;
// default :
// Console.WriteLine(100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 400000 * 0.03 + 600000 * 0.015 + (x - 1000000) * 0.01);
// Console.WriteLine();
// break;
// }
// Console.WriteLine();
// }
//第三题if
static void Test3()
{
Console.WriteLine("请输入利润:");
double x = double.Parse(Console.ReadLine());
double y = 0.0;
if (x <= 100000)
{
Console.WriteLine(100000 * 0.1);
}
else if (x <= 200000)
{
Console.WriteLine(100000 * 0.1 + (x - 100000) * 0.075);
}
else if (x <= 400000)
{
Console.WriteLine(100000 * 0.1 + 100000 * 0.075 + (x - 200000) * 0.05);
}
else if (x <= 600000)
{
Console.WriteLine(100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (x - 400000) * 0.03);
}
else if (x <= 1000000)
{
Console.WriteLine(100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 400000 * 0.03 + (x - 600000) * 0.015);
}
else if (x >= 1000000)
{
Console.WriteLine(100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 400000 * 0.03 + 600000 * 0.015 + (x - 1000000) * 0.01);
}
Console.WriteLine(y);
}
//第四题
static void Test4()
{
Console.WriteLine ("请输入第一个操作数:");
double firstOperator = double.Parse(Console.ReadLine());
Console.WriteLine("请输入第二个操作数:");
double secondOperator = double.Parse(Console.ReadLine());
double result = 0.0;
char Operator = '+';
Console.WriteLine("请输入四则运算符:");
Operator = char.Parse(Console.ReadLine());
switch (Operator)
{
case '+':
result=firstOperator +secondOperator ;
break ;
case '-':
result=firstOperator -secondOperator ;
break ;
case '*':
result=firstOperator *secondOperator ;
break ;
case '/':
result=firstOperator /secondOperator ;
break ;
}
Console.WriteLine(result);
}
}
}