0% found this document useful (0 votes)
8 views

Console Notes 1

Uploaded by

kahariironald
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Console Notes 1

Uploaded by

kahariironald
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

1

*************
Contains all the codes since day one

Kuda
Console.writeline(“ “)

console notes
Since day one
1

3
4
5 Code to print Average
6
7
8
9 Module Module1
10
11 Sub Main()
12 Dim test1, test2 As Single
13 Dim avarage As Double
14 Console.WriteLine("enter mark test 1 mark")
15 test1 = Console.ReadLine
16 Console.WriteLine("enter mark test 2 mark")
17 test2 = Console.ReadLine
18 avarage = (test1 + test2) / 2
19 Console.WriteLine("the avarage is " & avarage)
20 Console.ReadLine()
21
22 End
23
24

25
26
27 Module Module1
28
29 Sub Main()
30 Dim num1, num2 As Single
31 Dim resulte As Double
32 Console.WriteLine("enter mark num1")
33 num1 = Console.ReadLine
34 Console.WriteLine("enter mark num2")
35 num2 = Console.ReadLine
36 resulte = num1 Mod num2
37 Console.WriteLine("the resulte is" & resulte)
38 Console.ReadLine()
39
40
41 End Sub
2

42
43 End Module
44

45
3

46
4

47

48 The mode concept


49 Module Module1
50
51 Sub Main()
52 Dim year As Double
53 Console.WriteLine("enter year")
54 Console.ReadLine()
55 If year Mod 4 = 0 Then
56 Console.WriteLine("it is a leap year")
57 Console.ReadLine()
58 Else
59 Console.WriteLine("it is not a leap year")
60 Console.ReadLine()
61 End If
62 Console.ReadKey()
63
64 End Sub
65
66 End Module

67
68 Module Module1
69
70 Sub Main()
71 Dim year As Double
72 Console.WriteLine("enter year")
73 year = Console.ReadLine()
74 If year Mod 4 = 0 Then
75 Console.WriteLine("it is a leap year")
76 Console.ReadLine()
77 Else
78 Console.WriteLine("it is not a leap year")
79 Console.ReadLine()
80
81 End If
82 Console.ReadKey()
83
84 End Sub
85
86 End Module
87
88

89
90

91 The quadratic formula code


92 Imports System.Math
5

93 Module Module1
94
95 Sub Main()
96 Dim a, b, c As Integer
97 Dim x1, x2 As Double
98
99 Console.WriteLine("enter the value of A")
100 a = Console.ReadLine
101 Console.WriteLine("enter the value of b")
102 b = Console.ReadLine
103 Console.WriteLine("enter the value of c")
104 c = Console.ReadLine
105 x1 = (-b + Sqrt(b ^ 2 - 4 * a * c)) / (2 * a)
106 x2 = (-b - Sqrt(b ^ 2 - 4 * a * c)) / (2 * a)
107 Console.WriteLine("THE value for x1 " & x1)
108 Console.WriteLine("The value for x2 " & x2)
109 Console.ReadKey()
110
111 End Sub
112
113 End Module

114
115
116
117
118

119 Code for Changing from degrees to ferahights


120
121 Module Module1
122
123 Sub Main()
124 Dim temp, fera As Single
125 Console.WriteLine("enter tempereture in degrees")
126 temp = Console.ReadLine()
127 fera = (9 / 5 * temp) + 32
128 Console.WriteLine("the tempereture in ferahights is" & vbTab & fera)
129 Console.ReadKey()
130
131 End Sub
132
133 End Module
134

135
6

136

137 Code to calculate volume


138 Module Module1
139
140 Sub Main()
141 Dim volume As Single
142 Dim length, width, hight As Single
143 Console.WriteLine("enter lenght ")
144 length = Console.ReadLine
145 Console.WriteLine("enter hight ")
146 hight = Console.ReadLine
147 Console.WriteLine("enter width")
148 width = Console.ReadLine
149 volume = length * width * hight
150 Console.WriteLine("the volume is" & vbTab & volume)
151 Console.ReadKey()
152
153 End Sub
154
155 End Module

156

157
158

159

160 Code to use select case


161
162 Module Module1
163
7

164 Sub Main()


165 Dim name As String
166 Dim mark As Integer
167 Console.WriteLine("student name")
168 name = Console.ReadLine
169 Console.WriteLine("enter mark ")
170 mark = Console.ReadLine
171 Select Case mark
172 Case Is > 70
173 Console.WriteLine(name & "`s grade is A")
174 Case 60 To 69
175 Console.WriteLine(name & "`s grade is B")
176 Case 50 To 59
177 Console.WriteLine(name & "`s grade is C")
178 Case 45 To 49
179 Console.WriteLine(name & "`s grade is D")
180 Case 40 To 44
181 Console.WriteLine(name & "`s grade is E")
182 Case Else
183 Console.WriteLine(name & "`s grade is U")
184 End Select
185
186 Console.ReadKey()
187
188
189
190
191 End Sub
192
193 End Module
194
195

196

197

198
199

200 Code to calculate bonus


201
202 Module Module1
203
204 Sub Main()
205 Dim sales As Single
206 Dim bouns As Single
207 Console.WriteLine("enter sales ")
208 sales = Console.ReadLine
209 If sales > 2000 Then
210 bouns = 10 / 100 * sales
211 Else
212 bouns = 5 / 100 * sales
8

213
214
215 End If
216 Console.WriteLine("the bouns is " & bouns)
217 bouns = Console.ReadLine
218 Console.ReadKey()
219
220 End Sub
221
222 End Module
223

224

225

226 The for loop


227 Module Module1
228
229 Sub Main()
230 Dim index As Integer
231 For index = 1 To 12
232
233
234 Console.WriteLine("NUMBER" & vbTab & index & vbTab & "SQUARE OF NUMMBER" & vbTab & index *
235 2)
236
237 Next
238 Console.ReadKey()
239
240
241 End Sub
242
243 End Module
244

245
9

246
247

248

249
250 Module Module1
251
252 Sub Main()
253 Dim name As String
254 Dim mark As Single
255 Console.WriteLine("enter your name")
256 name = Console.ReadLine
257 Console.WriteLine("enter mark")
258 mark = Console.ReadLine
259
260
261 Select Case mark
262 Case Is > 70
263 Console.WriteLine(name & " your grade is A")
264 Case 60 To 69
265 Console.WriteLine(name & " your grade is B")
266 Case 50 To 59
267 Console.WriteLine(name & " your grade is C")
268 Case 40 To 49
269 Console.WriteLine(name & " your grade is D ")
270 Case Else
271 Console.WriteLine(name & " YOU HAVE FAILD")
272 End Select
273
274 Console.ReadKey()
275
276 End Sub
277
278 End Module
10

279
280

281 Pyramid programs

282

283
284 Module Module1
285
286 Sub Main()
287 Dim a, b, num As Integer
288 Console.WriteLine(" enter the number of rows ")
289 num = Console.ReadLine
290 For a = 1 To num
291 For b = 1 To a
292 Console.Write("*")
293 Next
294 Console.WriteLine("")
295 Next
296 Console.WriteLine("enter any key to exite")
297 Console.ReadKey()
298 End Sub
299
300 End Module
301

302

303
11

304
305 Module Module1
306
307 Sub Main()
308 Dim n, i, j As Integer
309 Dim m As Integer = 1
310 Console.WriteLine("enter nuber of rows")
311 n = Console.ReadLine
312 For i = n To 1 Step -1
313 For j = 1 To i
314 Console.Write("* ")
315
316 Next
317 Console.WriteLine("")
318 Next
319 Console.WriteLine("enter any key to exite")
320 Console.ReadKey()
321
322 End Sub
323
324 End Module
325

326
327
328 Module Module1
329
330 Sub Main()
331 Dim n, i, j, k As Integer
332 Dim m As Integer = 1
333 Console.WriteLine("enter number of rows ")
334 n = Console.ReadLine
335 For i = n To 1 Step -1
336 For j = 1 To m
337 Console.Write(" ")
338
339 Next
340 For k = 1 To 2 * i - 1
341 Console.Write("*")
342 Next
343 m += 1
344 Console.WriteLine("")
345 Next
346 Console.WriteLine("press any key to exit.....")
347 Console.ReadKey()
348
349 End Sub
350
351 End Module
12

352
353
354 Module Module1
355
356 Sub Main()
357 Dim n, i, j, k As Integer
358 Dim space As Integer = 1
359 Console.WriteLine("enter a number to show rows in a pattern")
360 n = Console.ReadLine
361 Console.WriteLine()
362 For i = 1 To n
363 For j = 1 To n - 1
364 Console.Write(" ")
365 Next
366 For k = 1 To 2 * i - 1
367 Console.Write("*")
368 Next
369 Console.WriteLine("")
370 n -= 1
371 Next
372 Console.ReadKey()
373
374
375
376 End Sub
377
378 End Modu

379

380
381
382 Module Module1
13

383
384 Sub Main()
385 Dim n, i, j As Integer
386 Console.WriteLine("enter number of rows ")
387 n = Console.ReadLine
388 For i = 1 To n
389 For j = 1 To i
390 Console.Write(" * ")
391 Next
392 Console.WriteLine("")
393 Next
394 For i = n To 1 Step -1
395 For j = 1 To i
396 Console.Write(" * ")
397
398 Next
399 Console.WriteLine("")
400 Next
401 Console.ReadKey()
402
403
404 End Sub
405
406 End Module

407

408
409

410
411 Module Module1
412
413 Sub Main()
414 Dim i, j, k, m, n As Integer
415 Console.WriteLine(" enter number of rows ")
416 n = Console.ReadLine
417
418 For i = n To 1 Step -1
419 For j = 1 To i - 1
420 Console.Write(" ")
421 Next
422 For k = 1 To m
423 Console.Write("*")
424 Next
425 m += 1
426 Console.WriteLine("")
427
428 Next
429 Console.ReadKey()
430
431
432 End Sub
433
434 End Modul
14

435 program to print right pyramd

436 Module Module1


437
438 Sub Main()
439 Dim i, j, k, m, n As Integer
440 Console.WriteLine("enter number of rows")
441 n = Console.ReadLine
442
443 For i = n To 1 Step -1
444 For j = 1 To i
445 Console.Write(" ")
446 Next
447 For k = 1 To m
448 Console.Write("*")
449 Next
450 Console.WriteLine("")
451 m += 1
452 Next
453 Console.ReadKey()
454
455
456 End Sub
457
458 End Module

459

460

462 Incremented and decremented half pyramid of numbers

463
464 Module Module1
465
466 Sub Main()
467 Dim a, b, num As Integer
468 Console.WriteLine("enter number of rows")
469 num = Console.ReadLine
470 For a = num To 1 Step -1
471 For b = 1 To a
472 Console.Write(" {0} ", b)
473 Next b
474 Console.WriteLine("")
475 Next a
476 For a = 1 To num
477 For b = 1 To a
478 Console.Write(" {0} ", b)
479
15

480 Next b
481 Console.WriteLine("")
482 Next a
483
484 Console.ReadKey()
485
486 End Sub
487
488 End Module
489

490

491

492 Floyd `s pyramid of numbers

493
494 Module Module1
495
496 Sub Main()
497 Dim n, j, k As Integer
498 Dim m As Integer = 1
499 Console.WriteLine("enter number of rows ")
500 n = Console.ReadLine
501 For j = 1 To n
502 For k = 1 To j
503 Console.Write(" {0} ", m)
504 m += 1
505 Next k
506 Console.WriteLine("")
507 Next j
508 Console.ReadKey()
509
510
511 End Sub
512
513 End Module
514

515
16

516

517 Pyramid of numbers

518
519 Module Module1
520
521 Sub Main()
522 Dim i, j, k, n, l As Integer
523 Console.WriteLine("enter number of rows")
524 n = Console.ReadLine
525
526 For i = 1 To n
527 For j = 1 To n - i
528 Console.Write(" ")
529 Next
530 For k = 1 To i
531 Console.Write("{0}", k)
532 Next
533 For l = i - 1 To 1 Step -1
534 Console.Write("{0}", l)
535
536 Next
537 Console.WriteLine("")
538 Next
539 Console.ReadKey()
540
541 End Sub
542
543 End Module
544

545
17

546
547
548 Module Module1
549
550 Sub Main()
551 Dim a, b, num As Integer
552 Console.WriteLine(" enter number of rows ")
553 num = Console.ReadLine
554 For a = 1 To num
555 For b = 1 To a
556 Console.Write("{0}", b)
557 Next
558 Console.WriteLine("")
559 Next
560 Console.ReadKey()
561
562 End Sub
563
564 End Module
565

566
567

568 Algo 1

569

570

571
18

572 Module Module1


573
574 Sub Main()
575 Dim i, j As Integer
576 Console.WriteLine("i" & vbTab & "j" & vbTab & "i + j" & vbTab & "i * j")
577 For i = 1 To 3
578 For j = 2 To 6
579 Console.WriteLine(i & vbTab & j & vbTab & i + j & vbTab & i * j)
580 Next j
581 Console.WriteLine("")
582 Next i
583 Console.ReadKey()
584
585 End Sub
586
587 End Module
588

589

590 alogorithm

591

592 Module Module1


593
594 Sub Main()
595 Dim num, mark, count As Integer
596 Console.WriteLine("enter number ")
597 num = Console.ReadLine
598
599 For count = 1 To num
600 Console.WriteLine("enter mark")
601 mark = Console.ReadLine
602 If mark < 50 Then
603 Console.WriteLine("fail")
604 ElseIf mark > 80 Then
605 Console.WriteLine("merit")
606 Else
607 Console.WriteLine("pass")
608 End If
609
610 Next
611 Console.ReadKey()
612
613
614 End Sub
615
616 End Module
617

618
19

619

620 Pascals triangel

621 Module Module1

622
623 Sub Main()
624 Dim num, blank, i, j As Integer
625 Dim c As Integer = 1
626 Console.WriteLine("Enter number of rows in the pascals triangle")
627 num = Console.ReadLine
628 For i = 0 To num - 1
629 For blank = 1 To num - i
630 Console.Write(" ")
631 Next blank
632 For j = 0 To i
633 If j = 0 OrElse i = 0 Then
634 c = 1
635 Else
636 c = c * (i - j + 1) / j
637 End If
638 Console.Write("{0} ", c)
639 Next
640 Console.WriteLine("")
641 Next
642 Console.ReadKey()
643
644 End Sub
645
646 End Module
647

648
20

649 PASCALS TRIANGLE


650 Imports System
651
652 Module Program
653 Sub Main()
654 Dim num, blank, i, j As Integer
655 Dim c As Integer = 1
656 Console.WriteLine("enter numb of row")
657 num = Console.ReadLine
658 For i = 0 To num - 1
659 For blank = 1 To num - i
660 Console.Write(" ")
661 Next blank
662 For j = 0 To i
663 If j = 0 OrElse i = 0 Then
664 c=1
665 Else
666 c = c * (i - j + 1) / j
667 End If
668 Console.Write("{0}", c)
669 Next
670 Console.WriteLine("")
671 Next
672 Console.ReadKey()
673
674 End Sub
675 End Module
676

677
678

679 Module Module1


680 Sub Main()
681 Dim num, total As Integer
682 total = 0
683 ' Console.ReadLine()
684 num = 0
685 Console.WriteLine("enter numbers btwn 1 to 10")
686 While num <= 10
687 total = total + num
688 num = num + 1
689 Console.WriteLine(total)
690 End While
691 Console.ReadKey()
692
693
694 End Sub
695
696 End Module
697
21

698

699 CODE TO FIND IF A TRIANGLE IS WRITE ANGLED OR NOT


700
701 Module Program
702 Sub Main()
703 Dim side_a, side_b, side_c As Integer
704 Console.WriteLine("enter value for side A ")
705 side_a = Console.ReadLine
706 Console.WriteLine("enter value for side B ")
707 side_b = Console.ReadLine
708 Console.WriteLine("enter value for side C ")
709 side_c = Console.ReadLine
710 If side_a * side_b = side_b * side_c * side_c Then
711 Console.WriteLine("the triangle id right angled")
712 Else
713 Console.WriteLine("the triangle is not right angled")
714 End If
715 Console.WriteLine()
716 Shell("cmd/c pause",AppWinStyle.NormalFocus,True)
717
718 End Sub
719 End Module
720

721

722 PASICALS TRIANGLE CODE


723 Module Module1
724
725 Sub Main()
726 Dim numRows As Integer
727 numRows = InputBox("Enter the number of rows in Pascal's Triangle: ")
728 Dim triangle(numRows - 1, numRows - 1) As Integer
729 For i = 0 To numRows - 1
22

730 For j = 0 To i
731 If j = 0 Or j = i Then
732 triangle(i, j) = 1
733 Else
734 triangle(i, j) = triangle(i - 1, j - 1) + triangle(i - 1, j)
735 End If
736 Next j
737 Next i
738 For i = 0 To numRows - 1
739 For j = 0 To i
740 Console.Write(triangle(i, j) & " ")
741 Next j
742 Console.WriteLine()
743 Next i
744 Console.ReadKey()
745
746 End Sub
747
748
749 End Module
750 Code to show the largest num
751 Module Module1
752
753 Sub Main()
754 Dim large, count, num As Integer
755 large = 0
756 count = 0
757 While count < 4
758 Console.WriteLine("enter num")
759 num = Console.ReadLine()
760 count = count + 1
761 If num > large Then
762 large = num
763 End If
764 Console.WriteLine()
765 End While
766 Console.WriteLine("LARGE =" & large)
767 Console.ReadKey()
768
769 End Sub
770
771 End Module
772

773

774 Code to accept positive numbers and out put the average
775 Module Module1
776
777 Sub Main()
778 Dim TOTAL, AVERAGE, NUM As Integer
779 For COUNT = 1 To 5
780 Console.WriteLine("INPUT NUMBER")
781 NUM = Console.ReadLine
782 TOTAL = TOTAL + NUM
783 Next
784 AVERAGE = TOTAL / 5
23

785 Console.WriteLine("avarage is" & AVERAGE)


786 Console.ReadKey()
787
788
789 End Sub
790
791 End Module
792
793

794

795

796

797 Do until loop


798 Module Module1
799
800 Sub Main()
801 Dim x As Integer = 1
802 Do
803 x = x + 2
804 Console.WriteLine(x)
805 Loop Until x = 10
806
807 Console.ReadKey()
808
809 End Sub
810
811 End Module
812

813
814
24

815

816

817

818

819

820

821

822

823

824

825

826

827 Code to find out how many numbers are in


828 a number
829 Imports System.Console
830 Module Module1
831
832 Sub Main()
833 Dim count As Integer
834 Dim x As Integer
835 WriteLine("enter number ")
836 x = ReadLine()
837 Do
838 x = x / 10
839 count += 1
840 Loop Until x < 1
841 WriteLine(count)
842 ReadKey()
843
844
845 End Sub
846
847 End Modul
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
25

866 Module Module1


867
868 Sub Main()
869 Dim name(3) As String
870 Dim mark(3) As Integer
871 Dim grade(3) As String
872 'Dim index As Integer
873 For index = 0 To 3
874 Console.WriteLine("enter your name" & vbTab & index)
875 name(index) = Console.ReadLine
876 Console.WriteLine("enter your mark " & vbTab & index)
877 mark(index) = Console.ReadLine
878 Select Case mark(index)
879 Case 70 To 100
880 grade(index) = "A"
881 Case 60 To 69
882 grade(index) = "B"
883 Case 50 To 59
884 grade(index) = "C"
885 Case 45 To 49
886 grade(index) = "D"
887 Case 40 To 44
888 grade(index) = "E"
889 Case 0 To 39
890 grade(index) = "F"
891 Case Else
892 grade(index) = "Error"
893 End Select
894 Next
895 For index = 0 To 3
896 Console.WriteLine("NAME :" & vbTab & name(index) & vbTab & "MARK : " & vbTab & mark(index)
897 & vbTab & "GRADE" & vbTab & grade(index))
898 Next
899 Console.ReadKey()
900 End Sub
901
902 End Module
903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920
26

921

922 Liner search


923 Imports System.Console
924 Module Module1
925
926 Sub Main()
927 Dim exams(4) As Integer
928 Dim index, mark As Integer
929 Dim count As Integer = 0
930 For index = 0 To 4
931 WriteLine("enter your mark" & index)
932 exams(index) = ReadLine()
933
934 Next index
935 Dim found, missing As Boolean
936 found = False
937 missing = False
938 WriteLine("enter your srch key")
939 mark = ReadLine()
940 Do
941 If mark = exams(count) Then
942 found = True
943 Else
944 missing = True
945 End If
946 count += 1
947
948 Loop Until found = True Or count > 4
949 If found = True Then
950 WriteLine("value has been found")
951 Else
952 WriteLine("vlue is missing")
953 End If
954 ReadKey()
955
956
957 End Sub
958
959 End Module
960

961
962
27

963
964

965

966 Public Class Form1


967
968 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
969 Dim amount, num, intrestrate As Integer
970 Dim balance, obtained, interest, rate As Integer
971 amount = TextBox1.Text
972 num = TextBox2.Text
973 intrestrate = TextBox3.Text
974 balance = amount * (num + intrestrate)
975 TextBox4.Text = balance
976 interest = balance - amount
977 TextBox5.Text = interest
978 obtained = balance - amount
979 TextBox6.Text = obtained
980 rate = (interest / amount)
981 TextBox7.Text = rate
982 End Sub
983
984 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
985 TextBox1.Clear()
986 TextBox2.Clear()
987 TextBox3.Clear()
988 TextBox4.Clear()
989 TextBox5.Clear()
990 TextBox6.Clear()
991 TextBox7.Clear()
992
993 End Sub
994
995 Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
996 End
997
998 End Sub
999 End Class

1000
1001
28

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014 Imports System.Console
1015 Module Module1
1016
1017 Sub Main()
1018 Dim exams(7) As Integer
1019 Dim index, mark As Integer
1020 Dim count As Integer = 0
1021 For index = 0 To 6
1022 WriteLine("enter your mark" & index)
1023 exams(index) = ReadLine()
1024
1025 Next index
1026 Dim found, missing As Boolean
1027 found = False
1028 missing = False
1029 WriteLine("enter your srch key")
1030 mark = ReadLine()
1031 Do
1032 If mark = exams(count) Then
1033 found = True
1034 Else
1035 missing = True
1036 End If
1037 count += 1
1038 exams(index) += 1
1039 Loop Until found = True Or count > 6
1040 If found = True Then
1041 WriteLine("value has been found" & vbTab & "at index " & exams(index))
1042 Else
1043 Console.WriteLine("value has not been found")
1044 End If
1045 ReadKey()
1046 End Sub
1047
1048 End Module

1049
29

1050
1051

1052

1053 Nested for loop used to enter a set of marks


1054

1055 Imports System.Console


1056 Module module1
1057 Sub Main()
1058 Dim mark, Avg As Single
1059 Dim name As String
1060 Dim total As Integer = 0
1061 For i = 1 To 2
1062 Console.WriteLine("ENTER NAME OF STUDENT")
1063 name = ReadLine()
1064 For j = 1 To 5
1065 Console.WriteLine("enter mark")
1066 mark = ReadLine()
1067 total = total + mark
1068 Next j
1069 Avg = total / 5
1070 Console.WriteLine("the avarage is " & Avg)
1071 Next i
1072 ReadKey()
1073 End Sub
1074 End Module
1075

1076

1077
30

1078

1079

1080

1081 Module Module1


1082 'notes on 2d arry
1083 Sub Main()
1084 Dim matrix(2, 3) As Integer
1085 Dim i, j As Integer
1086 For i = 0 To 2 ' rows
1087 For j = 0 To 3 ' colums
1088 Console.WriteLine("enter marks" & " (" & i & ", " & j & ") ")
1089 matrix(i, j) = Console.ReadLine
1090 Next j
1091 Next i
1092 For i = 0 To 3
1093 For j = 0 To 2
1094 Console.WriteLine(matrix(j, i) & "(" & j & "," & i & ")")
1095 Next
1096 Next
1097 Console.ReadKey()
1098 End Sub
1099
1100 End Module
1101

1102

1103

1104 Imports System.Console


1105 Module module1
1106 Sub Main()
1107 Dim chr(5) As String
1108 Dim cons As Integer = 0
1109 Dim vowels As Integer = 0
1110 Dim cap As Integer = 0
1111 Dim i As Integer
1112 For i = 0 To 5
1113 Console.WriteLine("ENTER ANY CHARACTOR AND PRESS ENTER")
1114 chr(i) = ReadLine()
1115 Select Case chr(i)
1116 Case "A" To "Z"
1117 cap += 1
1118 Case "a", "e", "i", "O", "u"
1119 vowels += 1
1120 Case Else
1121 cons += 1
1122 End Select
1123 'If chr(i) = Int(chr(i)) Then
1124 'cons -= 1
1125 'End If
1126 Next
1127 WriteLine("vowels" & vbTab & vowels)
1128 WriteLine("capital" & vbTab & cap)
1129 WriteLine("consonents" & vbTab & cons)
1130 ReadKey()
1131 End Sub
1132 End Module
1133

1134 BUBBLE SORT CODE


1135 Imports System.Console
1136 Module Module1
1137
1138 Sub Main()
1139 Dim arry(4) As Integer
1140 Dim j As Integer
1141 For j = 0 To 4
1142 WriteLine("enter number " & j)
1143 arry(j) = ReadLine()
1144
1145 Next j
31

1146 Dim x, i, n, num As Integer


1147 n = 3
1148 For i = 0 To n
1149 For x = 0 To 3
1150 If arry(x) > arry(x + 1) Then
1151 num = arry(x)
1152 arry(x) = arry(x + 1)
1153 arry(x + 1) = num
1154 End If
1155 Next
1156 For Each num1 As Integer In arry
1157 Write("{0}", num1 & vbTab)
1158 Next
1159 WriteLine(" ")
1160 Next
1161 For j = 0 To 4
1162 Write(arry(j) & " ")
1163 Next
1164 ReadKey()
1165 End Sub
1166
1167 End Module
1168

1169
1170

1171

1172 Imports System.Console


1173 Module Module1
1174
1175 Sub QuickSort(ByVal arr() As Integer, ByVal left As Integer, ByVal right As Integer)
1176 Dim i As Integer
1177 Dim j As Integer
1178 Dim pivot As Integer
1179 Dim temp As Integer
1180 'if the index is less than the right index , there's more than elemet in the partition
1181 If left < right Then
1182 'set the pivot to be the the first element in the arrry
1183 pivot = arr(left)
1184 'intializing i and j for the partition tracing
1185 i = left
1186 j = right
1187 'partition the arry by movng the elements less than the pivot to the left and those greter
1188 than the
1189 ' pivot to the right of the pivot
1190 While i <= j
1191 While arr(i) < pivot And i < right
1192 i = i + 1
1193 End While
1194 While arr(j) > pivot And j > left
1195 j = j - 1
1196 End While
1197 If i <= j Then
1198 'swapping elements as being traced by i and j
1199 temp = arr(i)
32

1200 arr(i) = arr(j)


1201 arr(j) = temp
1202 'incrementing and decrimenting accordingling
1203 i = i + 1
1204 j = j - 1
1205 End If
1206 End While
1207 'recursivly calling quicksort on the left and right partitions
1208 If left < j Then
1209 QuickSort(arr, left, j)
1210 End If
1211 If i < right Then
1212 QuickSort(arr, i, right)
1213 End If
1214 End If
1215 End Sub
1216 Sub main()
1217 Dim arr(9) As Integer
1218 Dim i As Integer
1219 For i = 0 To 9
1220 WriteLine("enter numbers ")
1221 arr(i) = ReadLine()
1222 Next i
1223 QuickSort(arr, 0, UBound(arr))
1224 ' WriteLine(String.Join(",", arr))
1225 For i = 0 To 9
1226 Console.Write(arr(i) & vbTab)
1227 Next
1228 ReadKey()
1229 End Sub
1230 End Module
1231

1232 ARRY QUICK SORT


1233 Module Module1
1234
1235 Sub Quicksort(ByVal arr() As Integer, ByVal left As Integer, ByVal right As Integer)
1236 Dim i As Integer
1237 Dim j As Integer
1238 Dim pivot As Integer
1239 Dim temp As Integer
1240 If left < right Then
1241 pivot = arr(left)
1242 i = left
1243 j = right
1244 While i <= j
1245 While arr(i) < pivot And i < right
1246 i = i + 1
1247 End While
1248 While arr(j) > pivot And j > left
1249 j = j - 1
1250 End While
1251 If i <= j Then
1252 temp = arr(i)
1253 arr(i) = arr(j)
1254 arr(j) = temp
1255 i = i + 1
1256 j = j - 1
1257 End If
1258 End While
1259 If left < j Then
1260 Quicksort(arr, left, j)
1261 End If
1262 If i < right Then
1263 Quicksort(arr, i, right)
1264 End If
1265 End If
1266 End Sub
1267 Sub MAIN()
1268 Dim arr(5) As Integer
1269 For i = 0 To 5
1270 Console.WriteLine("enetr numbers to be soterd " & i)
1271 arr(i) = Console.ReadLine
1272 Next
1273 Quicksort(arr, 0, UBound(arr))
1274 Console.WriteLine(String.Join(",", arr))
1275 Console.ReadKey()
33

1276 End Sub


1277
1278 End Module
1279

1280

1281
1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299
34

1300 Quick sort for letters


1301 Module Module1
1302
1303 Sub Quicksort(ByVal arr() As String, ByVal left As String, ByVal right As String)
1304 Dim i As String
1305 Dim j As String
1306 Dim pivot As String
1307 Dim temp As String
1308 If left < right Then
1309 pivot = arr(left)
1310 i = left
1311 j = right
1312 While i <= j
1313 While arr(i) < pivot And i < right
1314 i = i + 1
1315 End While
1316 While arr(j) > pivot And j > left
1317 j = j - 1
1318 End While
1319 If i <= j Then
1320 temp = arr(i)
1321 arr(i) = arr(j)
1322 arr(j) = temp
1323 i = i + 1
1324 j = j - 1
1325 End If
1326 End While
1327 If left < j Then
1328 Quicksort(arr, left, j)
1329 End If
1330 If i < right Then
1331 Quicksort(arr, i, right)
1332 End If
1333 End If
1334
1335 End Sub
1336 Sub main()
1337 Dim arr() As String = {"d", "c", "b", "a"}
1338 Quicksort(arr, 0, UBound(arr))
1339 Console.WriteLine(String.Join(",", arr))
1340 Console.ReadKey()
1341 End Sub
1342
1343 End Module
1344

1345

1346

1347

1348

1349

1350

You might also like