Help with for loops
Afficher commentaires plus anciens
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 commentaire
Walter Diolosa
le 13 Déc 2011
Réponse acceptée
Plus de réponses (1)
Wayne King
le 13 Déc 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?
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!