H. W 2: A class includes 20 female students and 30 male students, including 15 female students and 20 male students with black hair. If a person is randomly chosen from the class, what is the probability that the chosen person is a female student with black hair? Hint: (Female student with black hair ) = P(AU B)
Answer:
The probability that the chosen person is a female student with black hair is 15/50, or 3/10.
Using An assembly code
Read a 3 digit number from one row, then a 1 digit number from the second row. Subtract the 1 digit number from the 3 digit number, and display the result. Make sure you print your name first, then your output.
Sample Input
123
1
Output
Name Last name
122
Sample Input
100
1
Output
Name Last name
099 (or you can display 99 without the 0, either one is fine)
Sample Input
001
1
Output
Name Last name
0 (or you can display 000, either one is fine by me)
An example implementation of the algorithm you described in x86 assembly language using NASM syntax:
The Assembly Language Programsection .data
; Define your data here if needed
section .text
global _start
_start:
; Print your name here
; Read the 3-digit number
mov eax, 3 ; number of characters to read
mov ebx, 0 ; file descriptor (stdin)
mov ecx, buf ; buffer to store the input
mov edx, eax ; maximum number of characters to read
int 0x80 ; invoke the read system call
; Convert the input to a number
mov eax, buf
sub eax, '0' ; convert the hundreds digit
mov ebx, 10
imul ebx
mov ecx, buf+1
sub ecx, '0' ; convert the tens digit
add eax, ecx
imul ebx
mov ecx, buf+2
sub ecx, '0' ; convert the units digit
add eax, ecx
; Read the 1-digit number
mov eax, 1 ; number of characters to read
mov ebx, 0 ; file descriptor (stdin)
mov ecx, buf ; buffer to store the input
mov edx, eax ; maximum number of characters to read
int 0x80 ; invoke the read system call
; Convert the input to a number
mov ebx, 10
mov ecx, buf
sub ecx, '0' ; convert the digit
mul ebx
; Subtract the 1-digit number from the 3-digit number
sub eax, ecx
; Convert the result to a string
mov ebx, 10
div ebx
add edx, '0' ; convert the units digit
mov [result+2], dl
div ebx
add edx, '0' ; convert the tens digit
mov [result+1], dl
add eax, '0' ; convert the hundreds digit
mov [result], al
; Print the result
mov eax, 4 ; system call for write
mov ebx, 1 ; file descriptor (stdout)
mov ecx, result ; address of the string to print
mov edx, 3 ; number of characters to print
int 0x80 ; invoke the write system call
; Exit the program
mov eax, 1 ; system call for exit
xor ebx, ebx ; exit status
int 0x80
section .bss
buf resb 4 ; buffer for input (3 digits + newline)
result resb 4 ; buffer for output (3 digits + null terminator)
Note that this implementation uses system calls for input/output and assumes that the input is terminated by a newline character. You may need to modify it to suit your specific requirements or platform.
Read more about assembly language here:
https://brainly.com/question/30299633
#SPJ1