Help with for loops
Ältere Kommentare anzeigen
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 Kommentar
Walter Diolosa
am 13 Dez. 2011
Akzeptierte Antwort
Weitere Antworten (1)
Wayne King
am 13 Dez. 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?
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!