Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:50, najashohatee1234
Can online classes such as gradpoint track your ip location like if im taking a final and i give somebody else my account and they take the final for me will it show where they are taking the final from? and can this be countered with a vpn
Answers: 1
image
Computers and Technology, 22.06.2019 11:00, simbupls
Technician a says that the radiator usually cools better if the front air dam is removed. technician b says that when a condenser has a leak it can be repaired easily with epoxy. who is correct?
Answers: 1
image
Computers and Technology, 22.06.2019 16:20, Aleja9
It policy compliance and emerging technologies respond to the following: propose at least three control measures that organizations need to put in place to ensure that they remain complaint with emerging technologies and in a continually changing it environment. examine the correlation of effective configuration management and change control procedures to remain compliant with emerging technologies and it security changes.
Answers: 2
image
Computers and Technology, 23.06.2019 01:50, rhonda45801
Free points just awnser this. what should i watch on netflix
Answers: 2
Do you know the correct 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
Mathematics, 09.02.2020 22:07