Hi all,

Ive been working on sorting numbers in an array,

I can get the sorting to work somewhat but it will not loop through all of the numbers enter on the first try. This is an class project so im not looking for a full answer just some guidance.

Attached is the for loop I'm using with the array declaration.

Code:#include <stdio.h> #include <math.h> int n; int Data[50]; int i ; int printArray(void) { // prints all numbers in array for (i=0;i<n;i++){ printf("%d, ", Data[i]); } printf ("\n"); return (0); } int getArray(void) { // scanf numbers into array printf("Enter a list of Data to compute.\n"); scanf("%d", &n); printf("Please enter data points.\n"); for (i=0;i<n;i++){ printf("%d = ", i); scanf("%d", &Data[i]); } return (0); } int sort_sm(void){ //Sorts the array from smallest to largest. int swap = 0; int temp = 0; int i = 0; int n = 5; for(swap=1;swap<n-1;++swap) for(i=0;i<n-swap;++i) { if(Data[i]>Data[i+1]) { temp=Data[i]; Data[i]=Data[i+1]; Data[i+1]=temp; } } printArray(); //Print results return(0); }