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, 23.06.2019 01:20
Me with this program in c++ ! computers represent color by combining sub-colors red, green, and blue (rgb). each sub-color's value can range from 0 to 255. thus (255, 0, 0) is bright red. (130, 0, 130) is a medium purple. (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (in other word, equal amounts of red, green, blue yield gray).given values for red, green, and blue, remove the gray part. ex: if the input is 130 50 130, the output is: 80 0 80. thus, find the smallest value, and then subtract it from all three values, thus removing the gray.
Answers: 3
question
Computers and Technology, 23.06.2019 22:50
What is an rss reader used for? for creating a user account on a social new site
Answers: 2
question
Computers and Technology, 24.06.2019 17:00
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
question
Computers and Technology, 24.06.2019 20:50
Which key function of a business involves finding, targeting, attracting, and connecting with the right customers?
Answers: 3
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, 06.10.2020 01:01
question
Mathematics, 06.10.2020 01:01
question
Mathematics, 06.10.2020 01:01
question
Spanish, 06.10.2020 01:01