Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int nextVal = int.MaxValue, index = 0, n;
- //Random rnd = new Random();
- n = int.Parse(Console.ReadLine());
- int[] arr = new int[n];
- for (int i = 0; i < arr.Length; i++) //מעניק ערכים התחלתיים למערך
- {
- arr[i] = int.Parse(Console.ReadLine());
- //arr[i] = rnd.Next(1, 100) ; //מאתחל מערך בערכים רנדומליים
- }
- for (int i = 0; i < arr.Length; i++) //ממיין מערך
- {
- nextVal = int.MaxValue;
- for (int k = i; k < arr.Length; k++) //מחפש את האיבר הקטן ביותר שלא מוין
- {
- if (arr[k] < nextVal)
- {
- nextVal = arr[k];
- index = k;
- }
- }
- if (index != i) //מטרת התנאי היא לוודא שכל הערכים ימוינו ושלא ישוכתבו ערכים שעוד לא מוינו
- arr[index] = arr[i];
- arr[i] = nextVal;
- }
- foreach (int currentInt in arr) //מדפיס מערך
- Console.Write(currentInt + " ");
- Console.WriteLine();
- /* for(int i = 0; i < arr.Length; i++)
- * Console.Write(currentInt + " ");
- * Console.WriteLine(); */ //הדפסת מערך בעזרת לולאת for
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement