Question

Matlab write a code that - Prompt a user to enter 2 positive numbers (check the...

Matlab
write a code that
- Prompt a user to enter 2 positive numbers (check the that they are positives)
- find the LCM
- For each number test its multiplicity of 2 , 3 , 5 , 7 , 11

0 0
Add a comment Improve this question Transcribed image text
Answer #1

prompt = 'Enter x value:' ; % get x value
x = input(prompt)
prompt = 'Enter y value:'; % get y value
y = input(prompt)
xispositive = x>0        % determine x is positive
yispositive = y>0       % determine y is positive
disp(sprintf("Lcm of %d and %d is:",x,y,lcm(x,y)));           % print lcm of x and y
K=[2 3 5 7 11]          % multiplicity numbers
num = [x y]             % store x and y i num
for n = 1:length(num)   % for each num
    for c = 1:length(K) % for each multplicity
        if rem(num(n),K(c))==0 % calculate remainder
            disp(sprintf('%d multiplicity of %d is :',K(c),num(n),num(n)/K(c))); % if remainder 0 print quotient
        else
            disp(sprintf('%d multiplicity of %d is :',K(c),num(n),0));          % else print 0
        end
    end
end

Add a comment
Know the answer?
Add Answer to:
Matlab write a code that - Prompt a user to enter 2 positive numbers (check the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a code segment as specified below. // 1. Prompt the user to enter a positive...

    Write a code segment as specified below. // 1. Prompt the user to enter a positive integer number (say n). // 2. Calculate the sum of all the reciprocals of the numbers from 1 to n. For example, sum = (1 / 1) + ( 1 / 2 ) + ( 1 / 3) + ( 1 / 4 ) + … + ( 1 / n ) // 3. Print out the integer number and the sum. • NOTE:...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Q3. Write a MATLAB program that prompt the user to enter number of studentsN) Then, gave each stu...

    Q3. Write a MATLAB program that prompt the user to enter number of studentsN) Then, gave each students their grades(G1, G2,.GN), find the average grade (AV), the biggest grade (M) and the rank of the biggest grade(R). INPUT: 5,50,60,70,80,90), OUTPUT(70,90,5) Q3. Write a MATLAB program that prompt the user to enter number of studentsN) Then, gave each students their grades(G1, G2,.GN), find the average grade (AV), the biggest grade (M) and the rank of the biggest grade(R). INPUT: 5,50,60,70,80,90), OUTPUT(70,90,5)

  • 1) Write a MATLAB script to prompt a user to input two numbers, then assess whether...

    1) Write a MATLAB script to prompt a user to input two numbers, then assess whether the two numbers are equal or not. If the two numbers are equal, display that they are equal in the Command Window. If they are not equal, display that they are not equal in the Command Window. 2) Write a MATLAB script that prompts the user to enter the day of the week using the input function. If the information the user enters is...

  • MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers....

    MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers. Then prompt the user again to input as many numbers as they choose. Stop the program by inputting-1. Then, display the largest number and second largest number in the command window once the user kills the program. The built-in max function cannot be used. The figure below is an example of what the command window should look like when the code is ran. First...

  • USE C++ 2.) Write a program that will prompt the use to enter 10 numbers in...

    USE C++ 2.) Write a program that will prompt the use to enter 10 numbers in an array, then display: the 1st, the 5th and the last number. Example, if the user entered 1 2 3 4 5 6 7 8 9 10, the output shall be: 1st is 1 5th is 5 last is 10

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Write a test program that prompt the user to enter seven numbers, stores them in an...

    Write a test program that prompt the user to enter seven numbers, stores them in an array list and do the following: 1. Displays its elements (numbers) in increasing order by invoking a method with the following header that sorts the array: public static void sort(ArrayList<Integer>list) 2. Write a method that returns and displays the sum of all numbers (elements) of the ArrayList. Using the following header: public static double sum(ArrayList<Integer>list) 3. Write a method that removes the duplicate numbers...

  • Write a program in Java language to prompt the user to enter 3 integers (A, B,...

    Write a program in Java language to prompt the user to enter 3 integers (A, B, and C) then display these numbers from the lowest to the highest (sorted ascendingly) . Note that there are 6 different cases to handle proper order. As an example, a user entered 10 for A, 5 for B and 14 for C: the output of the program should look like this Enter number A? 10 Enter number B? 5 Enter number C? 14 Your...

  • in java Write an application called Squaring that will: • Prompt the user to enter an...

    in java Write an application called Squaring that will: • Prompt the user to enter an integer greater than 1. Your code for this should be type-safe and validate the number, meaning that your code should re-prompt the user for another entry if they enter anything other than an integer that is greater than 1. • Repeatedly square the integer until it exceeds 1 million, outputting the value each time after squaring. • Output the number of squarings required to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT