DIM nums(10)
CLS
FOR i = 0 TO 9
nums(i) = (RND * 10) + 1
PRINT nums(i)
NEXT
PRINT : PRINT "Press Enter to sort numbers"
rem pause to look at numbers
DO WHILE INKEY$ = "": LOOP
CLS
FOR loop1 = 0 TO 9
FOR loop2 = loop1 + 1 TO 9
IF nums(loop1) > nums(loop2) THEN SWAP nums(loop1), nums(loop2)
NEXT
NEXT
FOR i = 0 TO 9: PRINT nums(i): NEXT
You use the relevant formula.
first finding the whole number and then sort them out from least to greatest in answers
You can also use the Collections.sort() method to sort values in an array list. You can also use the Comparable Interface or Comparators for providing custom implementations of sorting algorithms for values inside an ArrayList.
You could always sort them, putting lesser numbers higher, until you have them all sorted. Then the least number would be at the top. Or you could subtract from all of them until one becomes zero. That would be the least.
That really depends on what sort of program you are trying to build, what do you want the program to do?
There are several methods available to sort numbers. A simple way to program sorting is the so-called "bubble-sort". This is inefficient for larger lists of numbers; in which case it is more convenient to use one of the faster algorithms, for example, "quick-sort".
The simplest would be to put the numbers into an int[] (integer array) and pass that to java.util.Arrays.sort(int[]) (a static method), which will sort the array in ascending numerical order. Use a float[] or double[] if you need to sort non-whole numbers. You can also use the Collections.sort(List) method to sort the List directly. Or the Collections.sort(List, Comparator) if you wish to specify your own sorting criteria.
Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.
for(i = 0; i < num_students; i ++){ sort(student[i]); } That's what you get when you're that specific!
Objects allow you to achieve a high level of abstraction as result your program can be used for working with different things. A simple example: you want to write a function which will sort array with integers numbers. It's known that if you want your function to sort numbers with floating point you basically have to rewrite your function again but this time for types double or/and float. Or you can use objects and write a class if you want which will do the same thing but for any type as far as certain set of mathematical operations is applicable for all of them.
decimal[] a = new decimal[20]; // initialize to some numbers for (int i = 0; i < 20; i++) { a[i] = i; } Array.Sort(a); //sorted in increasing order Array.Reverse(a); // decreasing foreach (decimal d in a) { Console.WriteLine(d); }
If you are using an array : sort using qsort() then take middle element.
I don't know, but if you write that in a sort of Hindi or gujarati way, You are writing " Ram."
Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.
Use a looping structure. The first step initialises a loop control variable, n, to zero. You then begin the loop by processing the nth element from the array (the process may be a simple print statement). You then increment n. Finally, you test the value of n; if it is less than 10 you start a new iteration of the loop, otherwise you proceed to the end of the flowchart.
Most computers nowadays come with some sort of word processing program like Microsoft Word - just open that program and follow the directions to get started!