# may someone please help me know why my program of arranging numbers in an array in ascending order is not working

Module VBModule
Sub Main()
dim arrMarks(0 to 9) as Integer
dim sum, minimum as Integer

dim p as Integer
dim ave as decimal
for i = 0 to 9

Console.WriteLine("Enter the input data into an array")
sum = sum + arrMarks(i)
next i
ave= sum/i
minimum = arrMarks(0)
for i = 1 to 9
if(arrMarks(i)<minimum) then
minimum=arrMarks(i)
end if
next i
arrMarks(0)= p(0)
for i = 0 to 9
for p = 0 to 9

if (arrMarks(i) < minimum) then
arrMark(i) = p=(p-1)
end if
next i
Console.WriteLine("you entered:"& arrMarks)
End Sub
End Module

+1 vote
answered Mar 2, 2021 by (88,520 points)

You got the for - next loop syntax wrong. Please read how it works here: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-next-statement

I've tried to fix things and it seems to work now.

I'm not sure why you needed the sum and minimum variables.

You can use a different sorting algorithm too. I picked bubble-sorting for its simplicity: in every iteration, you swap adjacent items if the left one is larger; this effectively makes the largest one rise to the top, just like bubbles in a fizzy-drink. :)

And here's the code:

```Module VBModule
Sub Main()
rem --== Variables ==--
dim arrMarks(0 to 9) as Integer
dim i as Integer
dim p as Integer
dim tmp as Integer

rem --== Initalise the array ==--
for i = 0 to 9
Console.Write("Enter the " & i & ". input data into an array: ")
next i

rem --== Bubble-sorting ==--
for i = 0 to 8
for p = 0 to 8 - i
if (arrMarks(p) > arrMarks(p + 1)) then
tmp = arrMarks(p)
arrMarks(p) = arrMarks(p + 1)
arrMarks(p + 1) = tmp
end if
next p
next i
rem Console.WriteLine("you entered:"& arrMarks)

rem --== Print the result ==--
Console.WriteLine("The array after sorting:")
for i = 0 to 9
Console.WriteLine(i & ". " & arrMarks(i))
next i
End Sub
End Module```

### Disclaimer

I do not work with Visual Basic, so probably the code could have been done better by someone who uses Visual Basic regularly.

answered Nov 27, 2023 by (240 points)

#include<stdio.h>

int main(){

int i,j,n,arr[100],temp;

printf("Enter limit:");

scanf("%d",&n);

printf("Enter values:");

for(i=0;i<n;i++)

{

scanf("%d",&arr[i]);

}

for(i=0;i<n;i++)

{

for(j=i+1;j<n;j++)

{

if(arr[i] < arr[j])

{

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

}

printf("\nAcsending order array:\n");

for(i=0;i<n;i++)

{

printf("%d\n",arr[i]);

}

}