1 a sonidan 2ta oldingi sonini qo’shganda a soni hosil bo’luvchi sonlar logikasini tuzing
Download 15.15 Kb.
|
6. do while
1) a sonidan 2ta oldingi sonini qo’shganda a soni hosil bo’luvchi sonlar logikasini tuzing. Maslan: 0,1,1,2,3,5,8,13….. Kodi: main(){ int n=100; int first=0; int second=1; while(first<=n){ print(first); int sum=first+second; first=second; second=sum; } } 2) Shunday archa yasaydigan logika tuzingki uning yulduzchalar qiymati soni berilishiga qarab archani katta-kichikligi o’zgarib borsin Kodi: import 'dart:math'; main(){ int n=5; int i=1; int rowNumber=(n/2).round(); int counter=1; while(counter<=rowNumber){ String probel=''; int k=1; while(k<=rowNumber-counter){ probel="$probel "; k++; } int j=1; String row=""; while(j<=i){ row="$row*"; j++; } print("$probel$row$probel"); i+=2; counter++; } } 3) Berilgan sondi nechi xonadan iborat ekanligini sanab beruvchi logika tuzing. (while) bilan tuzing Kodi: import 'dart:math'; main(){ int n=54; int i=0; while(i i++; } print(i); } 4) while yordamida birinchi 10 ta tub sonni chop eting: Kodi:
main(){ int ct=0,n=0,i=1,j=1; while(n<10) { j=1; ct=0; while(j<=i) { if(i%j==0) { ct++;} j++; } if(ct==2) { print(i); n++; } i++; } } 5)Palindromik bo'lgan birinchi 10 ta tub sonlarni chop eting Kodi: import 'dart:math'; main(){ int count = 0; for (int i = 10; i <= 1000; i++) { int num = i, revNum = 0; while (num != 0) { int digit = num % 10; num ~/= 10; revNum = revNum * 10 + digit; } if (revNum == i) { bool isPrime = true; for (int j = 2; j <= i / 2; j++) { if (i % j == 0) { isPrime = false; break; } }
print(i); count++; if (count == 10) { count = 0; } } } } } Download 15.15 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling