Skip to main content

Bubble borting q basic program. gw basic program for ICSE

1010 REM Bubble Sort program
1100 REM Initialize the array
1100 LET N = 10
1110 ARRAY A
1120 GOSUB 3000
1130 REM Print the random array
1140 PRINT "Random list:"
1150 GOSUB 4000
1160 REM Sort the array
1170 GOSUB 2000
1180 PRINT "Sorted list:"
1200 REM Print the sorted array
1210 GOSUB 4000
1220 END
2000 REM Bubble sort the list A of length N
2010 FOR I = 1 TO N - 1
2020 FOR J = 1 TO N - I
2030 IF A[J] <= A[J+1] THEN GOTO 2070
2040 LET X = A[J]
2050 LET A[J] = A[J+1]
2060 LET A[J+1] = X 
2070 NEXT J
2080 NEXT I
2090 RETURN
3000 REM Create a random list of N integers
3030 FOR I = 1 TO N
3040 LET A[I] = FLOOR(RAND(100))
3070 NEXT I
3090 RETURN 
4000 REM PRINT the list A
4010 FOR I = 1 TO N
4020 PRINT A[I];
4030 PRINT ", ";
4040 NEXT I

Comments

Popular posts from this blog

Class x_ Blue j java question solve(Important)

Section – A Answer any four of the following : 1 . Write a Program to calculate charges for sending particles when the charges are as follows For the first 1KG  Rs.15.00  , For additional weight , for every 500gm or fraction thereof: Rs 8.00 Ans class Prog1 { static void test(double wt)//user enters the weight in KGs { System.out.println(“Parcel  Weight is “+wt); int icharge = 15; System.out.println(“Initial  charge is “+icharge); int rwt = (int)((wt-1)*1000); System.out.println(“Remaining  weight after deducing 1Kg “+rwt); int rcharge = (rwt/500)*8; System.out.println(“Charge  excluding fractional part is Rs.”+(icharge+rcharge)); int fcharge = (rwt%500>0)?8:0; System.out.println(“Charge  for fractional part is Rs. “+fcharge); int tcharge = icharge+rcharge+fcharge; System.out.println(“Total  Charge is Rs. “+tcharge); } } 2 . A special two-digit number is such that when the sum of its digits is added to the product of its digits , the res...