-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment8.2main.dart
170 lines (148 loc) · 4.55 KB
/
Assignment8.2main.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
import 'dart:io';
import 'dart:math';
void main() {
//Question#1:display counting from 1 to 5 using for loop
for (int i = 1; i <= 5; i++) {
print(i);
}
//Question#2:display product of odd number from 0-10 using for loop
int product = 1;
for (int i = 1; i <= 10; i = i + 2) {
product = product * i;
}
print(product);
//Question#3:input number from suer and print its table using for loop
stdout.write('Enter the number u want table');
String? tableinstr = stdin.readLineSync();
int table = int.parse(tableinstr!);
for (int i = 1; i <= 10; i++) {
print('$table * $i=${table * i}');
}
//Question#4:input number from user and print its square of sum using for loop till that number
stdout.write('Enter the number u want till sum');
String? sumsquareinstr = stdin.readLineSync();
int sumsquare = int.parse(sumsquareinstr!);
int sums = 0;
for (int i = 1; i <= sumsquare; i++) {
sums = sums + (i * i);
}
print(sums);
//Question#5:input number from user and show highest and lowest number
stdout.write('Enter the number u want till max and min');
String? maxmininstr = stdin.readLineSync();
int maxmin = int.parse(maxmininstr!);
int max = maxmin % 10;
int min = maxmin % 10;
int reminder;
int no = maxmin ~/ 10;
for (int i = no; i >= 1; i = i ~/ 10) {
reminder = i % 10;
if (reminder > max) {
max = reminder;
} else if (reminder < min) {
min = reminder;
}
}
print('The max no is: $max');
print('The min no is: $min');
//Question#6:input number from user and show value of x and range
stdout.write('Enter the value of x');
String? xinstr = stdin.readLineSync();
int x = int.parse(xinstr!);
stdout.write('Enter the range');
String? rangeinstr = stdin.readLineSync();
int range = int.parse(rangeinstr!);
double density;
double sum = 0;
for (int i = 0; i < range; i++) {
density = pow(x, i).toDouble();
sum = sum + (1 / density);
}
print('Sum of series is : $sum');
//Question#7:print the following series
for (int i = 4; i <= 40; i = i + 3) {
print(i);
}
//Question#8:print the following series
for (int i = 1; i <= 40; i = i + 3) {
if (i % 2 == 0) {
print(-i);
} else {
print(i);
}
}
//Question#9:input a number and tell its perfect or not
stdout.write('Enter the number to find its perfect');
String? perfectinstr = stdin.readLineSync();
int perfect = int.parse(perfectinstr!);
int sumss = 0;
int mid = perfect ~/ 2;
for (int i = 1; i <= mid; i++) {
if (perfect % i == 0) {
sum = sum + i;
}
}
if (sums == perfect) {
print('its a perfect number');
} else {
print('its not a perfect number');
}
//Question#10:input a number and tell its prime or composite
stdout.write('Enter the number to find its prime');
String? primeinstr = stdin.readLineSync();
int prime = int.parse(primeinstr!);
int pcheck = 1;
for (int i = 2; i <= prime ~/ 2; i++) {
if (prime % i == 0) {
pcheck = 0;
break;
}
}
if (pcheck == 1) {
print('its a prime no');
} else {
print('its a composite no');
}
//Question#11:take input from user and print till no
for (int i = 1; i <= 5; i++) {
stdout.write('Enter the number ');
String? contnoinstr = stdin.readLineSync();
int contno = int.parse(contnoinstr!);
if (contno <= 0) {
continue;
}
print('You entered $contno');
}
//Question#12:odd sum from 1-100
int sumodd = 0;
for (int i = 0; i <= 100; i++) {
if (i % 2 != 0) {
sumodd = sumodd + i;
}
}
print(sumodd);
//Question#13:Take input from user if number less then 0 then it breaks the loops
for (int i = 0; i <= 5; i++) {
stdout.write('Enter the number');
String? breaknoinstr = stdin.readLineSync();
int breakno = int.parse(breaknoinstr!);
if (breakno <= 0) {
break;
}
print('The number is ${breakno}');
}
//Question#14:Take 2 number as input from user and display their GCD
stdout.write('Enter the first number to find GCD');
String? firstgcdinstr = stdin.readLineSync();
int firstgcd = int.parse(firstgcdinstr!);
stdout.write('Enter the second number to find GCD');
String? secondgcdinstr = stdin.readLineSync();
int secondgcd = int.parse(secondgcdinstr!);
int? gcd;
for (int i = 1; i <= firstgcd && i <= secondgcd; i++) {
if (firstgcd % i == 0 && secondgcd % i == 0) {
gcd = i;
}
}
print(gcd);
}