以下说法错误的是void main(){ state=1; while(1) { switch(state) { case 0x01:setup();break; case 0x02:run();break; } }}void setup(){ Buzzer=1;Led=1;while(1) { if(Key==0){state=0x02;goto exit;} }exit:return;}void run(){ Buzzer=0;Led=0; while(1) { if(Key==0){state=0x01;goto exit;} } exit:return;}
A: 共有两个状态
B: Buzzer=1;Led=1;实现声光报警
C: Buzzer=1;Led=1;全停
D: if(Key==0){state=0x01;goto exit;} 按下按键,转到第一个状态
A: 共有两个状态
B: Buzzer=1;Led=1;实现声光报警
C: Buzzer=1;Led=1;全停
D: if(Key==0){state=0x01;goto exit;} 按下按键,转到第一个状态
举一反三
- 定义状态机当前状态为state ,次态为next _state; 输入a,输出b, 则下列为Mealy状态机的写法是: A: always@(posedge clk)case (state )0:next_state<=1;1:next_state<=x; B: always@(posedge clk)case (state )0: if(a==0)next_state<=1; else next_state<=x;1:next_state<=x; C: always@(posedge clk)case (state )0: if(state==0)next_state<=1; else next_state<=x;1:next_state<=x; D: 以上都是正确的
- 中国大学MOOC: 读下列程序:void main(){ int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0: a++; break; case 1: b++; break; } case 2: a++; b++; break; } printf(
- 有如下程序: void main() { int x=1,a=0,b=0; switch (x) { case 0: b++; break; case 1: a++; break; case 2: a++;b++; break; } printf("a=%d,b=%d",a,b); }
- 下列程序的输出结果是()。 using System; class Program { public static void Main(string[] args) { int x=1,a=0,b=0; switch(x) { case 0: b++; break; case 1: a++; break; case 2: a++; b++; break; } Console.WriteLine(“a={0},b={1}”,a,b); } }
- 有以下程序:#include void main(){ int x=1, y=0, a=0, b=0; switch (x) { case 1: switch(y) { case 0: a++; break; case 1: b++; break; } case 2: a++; b++; break; case 3: a++; b++; } printf(“a=%d, b=%d”, a, b);}程序的运行结果是__。 A: a=2,b=2 B: a=2,b=1 C: a=1,b=1 D: a=1,b=0