1.求分段函数的值。.
(x2+x-6,
x<0且x≠-3
y={x2-5x +6,
0≤x<5且x≠2及x≠3
r2-r-1,
其他
用i语句实现,分别输出x=-5.0,-3.0,1.0,2.0,2.5,3.0,5.0时的y值。
2.输人一个百分制成绩,要求输出成绩等级A、B、C、D、E。其中90分~100分为A,80分~89分为B,70分~79分为C,60分-69分为D,60分以下为E。
要求:
(1)分别用if语句和switch语句实现。
(2)输人百分制成绩后要判断该成绩的合理性,对不合理的成绩应输出出错信息。
3.硅谷公司员工的工资计算方法如下:
(1)工作时数超过120小时者,超过部分加发15%。
(2)工作时数低于60小时者,扣发700元。
(3)其余按每小时84元计发。
试编程按输人的工号和该号员工的工时数,计算应发工资。
4.设计程序,完成两位数的加、减、乘、除四则运算,即产生两个两位随机整数,再输入一个运算符号,做相应的运算,并显示相应的结果。
5.建立5x6矩阵,要求输出矩阵第n行元素。当n值超过矩阵的行数时,自动转为输出矩阵最后一行元素,并给出出错信息。
x=[-5 -3 1 2 2.5 3 5]
if x<0&x~=-3
y=x*x+x-6
else if (x>=0&x<5)&(x~=2&x~=3)
y=x*x-5*x+6
else y=x.*x-x-1
end
end
a=input('')
if a>=90&a<=100
disp('A')
else if a<90&a>=80
disp('B')
else if a<80&a>=70
disp('C')
else if a<70&a>=60
disp('D')
else if a<60&a>=0
disp('E')
else disp('error')
end
end
end
end
end
a=input('')
if a>=90&a<=100
b=1
else if a<90&a>=80
b=2
else if a<80&a>=70
b=3
else if a<70&a>=60
b=4
else if a<60&a>=0
b=5
else disp('error')
end
end
end
end
end
switch(b)
case 1
disp('A')
case 2
disp('B')
case 3
disp('C')
case 4
disp('D')
case 5
disp('E')
end
n=input('工号:')
m=input('工作时间:')
if m>=120
y=m*84+m*84*0.15
disp(y)
else if m<120&m>=60
y=84*m
disp(y)
else y=m*84-700
disp(y)
end
end
a=randi([10 99])
b=randi([10 99])
c=input('请输入运算符:','s')
switch(c)
case '+'
z1=a+b
case '-'
z1=a-b
case '*'
z1=a*b
case '/'
z1=a/b
end
p=rand(5,6)
try
n=input('请输入要输出的行数:')
q=p(n,:)
catch
disp('error')
end