Question: Write a program in MATLAB/Octave that generates prime numbers and writes them in the following format. A prime number is a number that is divisible
Write a program in MATLAB/Octave that generates prime numbers and writes them in the following format. A prime number is a number that is divisible only by itself.
Basically one 2, two 3s, three 5s and so on must be printed (separated with commas) and they should be aligned with last row's last character. Get N as input from the user and print all prime numbers smaller than or equal to N in aforementioned format using Nested For Loops. You can NOT use isPrime() function of MATLAB/Octave. Sample runs: >> hwl Please enter a number: 5 2 3,3 5,5,5 >> hwl Please enter a number: 15 2 3,3 5,5,5 7,7,7,7 11, 11, 11, 11, 11 13, 13, 13, 13, 13, 13
Step by Step Solution
3.41 Rating (170 Votes )
There are 3 Steps involved in it
clc clear all N input Enter a number count 0 Nnew ... View full answer
Get step-by-step solutions from verified subject matter experts
