3-laboratoriya ishi.
Narzullayev Saidakbar
1000 gacha bulgan sonlarni ichida faqat oxiri 5 bilan tugagan sonlarni kupaytmasini hisoblaydigan formulani toping
Dastur kodi.
void main() {
int n = 1000;
int prod = 1;
for (int i = 0; i < n; i++) {
if (i % 10 == 5) {
prod *= i;
}
}
print(prod);
}
Dastur natijasi:
Birdan mingacha bólgan 3 honali va 2 honali sonlardan faqat juftlarini chiqaradigan logika tuzing.
Dastur kodi
void main() {
for (int i = 0; i < 1000; i++) {
if (i > 9 && i < 1000 && i % 2 == 0) {
print(i);
}
}
}
Dastur natijasi
Berilgan sonni nechi xonadan iborat ekanligini sanab beruvchi logika tuzing.
Dastur kodi
import 'dart:io';
main() {
print("Sonni kiriting: ");
int son = int.parse(stdin.readLineSync()!);
int xonalar_soni = 0;
while (son > 0) {
son = son ~/ 10;
xonalar_soni++;
}
print("Ushbu son $xonalar_soni xonali son");
}
Dastur natijasi
factorialni hisoblaydigan dastur tuzing.
Dastur kodi
import 'dart:io';
void main() {
print("Son kiriting: ");
int n = int.parse(stdin.readLineSync()!);
int factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
}
print("$n! = $factorial");
}
Dastur natijasi
Berilgan son Palindrom yoki Palindrom emasligini aniqlovchi logika tuzing
Dastur kodi
import 'dart:io';
void main() {
print("Son kiriting: ");
int son = int.parse(stdin.readLineSync()!);
int a = son;
int m = 0;
while (a > 0) {
m = m * 10 + a % 10;
a = a ~/ 10;
}
if (m == son) {
print("Palindrom");
} else {
print("Palindrom emas");
}
}
Dastur natijasi
Do'stlaringiz bilan baham: |