Answer Key
University
California State UniversityCourse
COMP 122 | Computer Architecture and Assembly Language and LabPages
5
Academic year
2022
NyiH
Views
15
int main () { enum { A , B , C , D } state ; int input ; int output ; state = A ; input = read_input (); switch ( state ) { case ( A ): output = 0 ; if ( input == 0 ) { state = A ;} else { state = B ;} break ; case ( B ): output = 0 ; if ( input == 0 ) { state = A ;} else { state = C ;} break ; case ( C ): output = 0 ; if ( input == 0 ) { state = D ;} else { state = C ;} break ; case ( D ): output = 1 ; if ( input == 0 ) { state = A ;} else { state = B ;} break ; } write_output ( output ); return 0 ; }
C Programming: State Transition Logic with Enum and Switch
Please or to post comments