-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment9 main.dart
238 lines (211 loc) · 6.81 KB
/
Assignment9 main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import 'dart:io';
import 'dart:math';
void main() {
//Question#1:Take 5 integeres from user and dsiplay them without using the loop
stdout.write("enter the first value please");
int a = (int.parse(stdin.readLineSync()!));
stdout.write("enter the seocnd value please");
int a1 = (int.parse(stdin.readLineSync()!));
stdout.write("enter the third value please");
int a2 = (int.parse(stdin.readLineSync()!));
stdout.write("enter the fourth value please");
int a3 = (int.parse(stdin.readLineSync()!));
stdout.write("enter the fifth value please");
int a4 = (int.parse(stdin.readLineSync()!));
print('The first value is : $a');
print('The second value is : $a1');
print('The third value is : $a2');
print('The fourth value is : $a3');
print('The fifth value is : $a4');
//Question#2:Take 5 integeres from user in array then display them
final list1 = List.empty(growable: true);
for (int i = 0; i < 5; i++) {
stdout.write('Enter the array at index ${i} plzz');
String? listnoinstr = stdin.readLineSync();
int listno = int.parse(listnoinstr!);
list1.add(listno);
}
print(list1);
//Question#3:Take 5 integeres from user in array ,store them then avg and sum
int sum = 0;
final list2 = List.empty(growable: true);
for (int i = 0; i < 5; i++) {
stdout.write('Enter the array at index ${i} plzz');
String? list2noinstr = stdin.readLineSync();
int list2no = int.parse(list2noinstr!);
list2.add(list2no);
sum = sum + list2no;
}
print('The sum is $sum');
print('the avegerage is ${sum ~/ 5}');
//Question#4:input date and month and display total days till that month
final daysinmonth = <int>[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
stdout.write('Ente the day');
int days = int.parse(stdin.readLineSync()!);
stdout.write('Ente the month');
int month = int.parse(stdin.readLineSync()!);
int total = days;
for (int i = 0; i < month - 1; i++) {
total = total + daysinmonth[i];
}
print('total days are ${total}');
//Question#5:input age of different person & counts no of person between 50 and 60
stdout.write('eneter the total person');
int totalperson = int.parse(stdin.readLineSync()!);
int count = 0;
for (int i = 0; i < totalperson; i++) {
stdout.write('enter the age');
int age = int.parse(stdin.readLineSync()!);
if (age >= 50 && age <= 60) {
count = count + 1;
}
}
print('total number of people between age 50 & 60 are $count');
//Question#6:4 arrays having 5 elecements printing number ,square,cube,sum
final number = List<int>.filled(5, 0);
final square = List<int>.filled(5, 0);
final cube = List<int>.filled(5, 0);
final sums = List<int>.filled(5, 0);
int totalsum = 0;
for (int i = 0; i < 5; i++) {
number[i] = i;
square[i] = i * i;
cube[i] = i * i * i;
sums[i] = number[i] + square[i] + cube[i];
totalsum = sums[i] + totalsum;
}
print('number: ${number}');
print('square: ${square}');
print('cube: ${cube}');
print('sums: ${sums}');
print('Totalsum: ${totalsum}');
//Question#7:Take 10 input from user and display max no
int max;
List<int> numbers = [];
for (int i = 0; i < 10; i++) {
stdout.write('Enter the number $i: ');
int no = int.parse(stdin.readLineSync()!);
numbers.add(no);
}
max = numbers[0];
for (int i = 1; i < numbers.length; i++) {
if (max < numbers[i]) {
max = numbers[i];
}
}
print('Maxiumum number is: ${max}');
//Question#8:Take 10 input from user and display min no
int min;
List<int> numberss = [];
for (int i = 0; i < 10; i++) {
stdout.write('Enter the number $i: ');
int no = int.parse(stdin.readLineSync()!);
numbers.add(no);
}
min = numberss[0];
for (int i = 1; i < numberss.length; i++) {
if (min > numberss[i]) {
min = numberss[i];
}
}
print('Minimum number is: ${min}');
//Question#9:Take 5 input from user and display them in reverse order
List<int> order = [];
List<int> revorder = [];
for (int i = 0; i < 5; i++) {
stdout.write('Enter the number');
int a = int.parse(stdin.readLineSync()!);
order.add(a);
}
print('The Actural list is: ${order}');
for (int i = order.length - 1; i >= 0; i--) {
revorder.add(order[i]);
}
print('The reveresed list is: ${revorder}');
print('The reversed list using the list method ${order.reversed.toList()}');
//Question#10:Take input from user and find it in the list
List<int> search = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
stdout.write('Ente the number to find in list');
int as = int.parse(stdin.readLineSync()!);
int cool = 0;
for (int i = 0; i < search.length; i++) {
if (search[i] == as) {
print('the value of ${as} is found at index ${i}');
cool = cool + 1;
}
}
if (cool == 0) {
print('value not in list');
}
//Question#11:Take input from user and find no in the list using binary search
List<int> numbersss = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
int loc = -1;
int start = 0;
int end = 9;
int mid;
stdout.write('Enter the number to write');
int n = int.parse(stdin.readLineSync()!);
while (start <= end) {
mid = (start + end) ~/ 2;
if (numbersss[mid] == n) {
loc = mid;
break;
} else if (n < numbersss[mid]) {
end = mid - 1;
} else {
start = mid + 1;
}
}
if (loc == -1) {
print("the number $n is not in list");
} else {
print('$n found at $loc');
}
//Question#12:Take 5 input from user and then sort the list
int min1;
int temp;
List<int> sort = [];
for (int i = 0; i < 5; i++) {
stdout.write("enter the value at index $i: ");
int no = int.parse(stdin.readLineSync()!);
sort.add(no);
}
print('The unsorted list is: ');
print(sort);
for (int i = 0; i < 4; i++) {
min1 = i;
for (int j = i + 1; j < 5; j++) {
if (sort[j] < sort[min]) {
min1 = j;
}
if (min1 != i) {
temp = sort[i];
sort[i] = sort[min1];
sort[min1] = temp;
}
}
}
print('The Sorted list is: ');
print(sort);
//Question#13:Take 5 input from user and then sort the list using bubble sort
int temp1;
List<int> bubbles = [];
for (int i = 0; i < 5; i++) {
stdout.write("enter the value at index $i: ");
int number = int.parse(stdin.readLineSync()!);
bubbles.add(number);
}
print('The unsorted list is: ');
print(bubbles);
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
if (bubbles[j] > bubbles[j + 1]) {
temp1 = bubbles[j];
bubbles[j] = bubbles[j + 1];
bubbles[j + 1] = temp1;
}
}
}
print('The sorted list is: ');
print(bubbles);
}