subject

Im trying to figure out how to write a program that finds prime factors of a number. i have the following but it only works for the number 12 for some reason. % this program will determine if an integer is prime and determine
% its prime factors function main clear; clc; % define number(s) to be checked, call function, and print output
n = 12; [answer, primefactors] = primey(n); fprintf('is %i a prime? %s \n', n, answer) fprintf('the primefactors of %i are: \n' , n) fprintf('%i \n' , primefactors) n = 12; [answer, primefactors] = primey(n); fprintf('is %i a prime? %s \n', n, answer) fprintf('the primefactors of %i are: \n' , n) fprintf('%i \n' , primefactors) end % end of function main function [answer, primefactors] = primey(n); if mod(n,1)==0 & n/n==1 answer= 'yes'; else answer= 'no'; end for k= 2: n-1 if mod(n, k)==0 factors(k)=k; end [a, b]= find(factors> 0); b primefactors= [1: numel(b)-1] numel(b) for j= 1: numel(b)-1 if mod(b(j),j)==0 primefactors(j)=b(j) end end end end

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:10
Dameas communication challenge is due to which factor
Answers: 2
question
Computers and Technology, 22.06.2019 21:50
Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. thus your code should put 11 + 22 + 33 + + 4949 + 50*50 into total. use no variables other than k and total.
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
What is the biggest difference between section breaks and regular page breaks
Answers: 1
You know the right answer?
Im trying to figure out how to write a program that finds prime factors of a number. i have the foll...
Questions
question
Mathematics, 19.05.2020 19:01
Questions on the website: 13722360