Help with for loops
Show older comments
Trying to create a program that asks user to input a number (integer) and then generates a list of randomly generated numbers (integers) between ‘1’ and number that user entered. Their should not be any repetition of numbers in the list.
I have this so far and I can't seem to figure out how to not repeat the #'s and to display the inputted integer. I know I have to use a if command but don't know how to execute! I have attempted to use if and else statements but I am stuck.
clc;
x = input('Enter a integer: ');
for x=1:x,
k=round(rand*x);
fprintf('%d\n',k)
end
Any Help is most appreciated.
1 Comment
Walter Diolosa
on 13 Dec 2011
Accepted Answer
More Answers (1)
Wayne King
on 13 Dec 2011
x = input('Enter a integer:\n');
y = randperm(x);
fprintf('%d\n',y);
Why are you trying to put it in to a for loop?
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!