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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:30, alexdub9649
What is a costume plot? why is it important to a film or theater production?
Answers: 2
image
Computers and Technology, 23.06.2019 12:20, jshhs
When guido van rossum created python, he wanted to make a language that was more than other programming languages. a. code-based b. human-readable c. complex d. functional
Answers: 1
image
Computers and Technology, 23.06.2019 21:40, jeovontamarley
language consists of basic components, and they are called a. 3; mental images, concepts, and speech b. 2; language acquisition and linguistic relativity c. 3; heuristics, algorithms, and analogies d. 4; phonemes, morphemes, syntax, and semantics e. 2; words and grammar
Answers: 3
image
Computers and Technology, 24.06.2019 17:30, sanchez9211
Click on the tab on the ribbon to open the backstage view. file view insert review
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 in other subjects:

Konu
Health, 14.01.2021 14:50
Konu
Physics, 14.01.2021 14:50
Konu
Mathematics, 14.01.2021 14:50