|
Axborot texnologiyalari (Dasturlash)
|
bet | 1/3 | Sana | 18.11.2023 | Hajmi | 0,92 Mb. | | #100887 |
Bog'liq Amaliy topshiriq 1 с (2)
Axborot texnologiyalari (Dasturlash)
1-amaliy topshiriq.
Konsol oyna uchun:
ni hisoblovchi dastur tuzing;
Dastur kodi:
Dastur Natijasi:
Quyidagi masalaning dasturini tuzing:
“Sonni top” o`yini. Kompyuter 10 va 20 oralig`ida bitta son o`ylasin (tasodifiy sonlar hosil qilish orqali). Foydalanuvchini son kiritishga undaydi va qachonki, foydalanuvchi kompyuter o`ylagan sonni kiritmagunicha bu jarayon davom etadi.
Dastur kodi:
Dastur Natijasi:
(Piramida) Foydalanuvchi tomonidan butun son kiritilganda 1 dan 9 gacha, mazkur sonlar yordamida piramida shaklini chop etuvchi dastur kodini yozing (Sikl operatolaridan foydalangan holda yechilsin).
Kiruvchi ma’lumot
|
Chiquvchi ma’lumot
|
7
|
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
|
3
|
1
2 1 2
3 2 1 2 3
|
Dastur kodi:
#include
using namespace std;
void bir()
{
cout<<" 1 "<}
void ikki()
{
cout<<" 2 1 2 "<}
void uch()
{
cout<<" 3 2 1 2 3 "<}
void turt()
{
cout<<" 4 3 2 1 2 3 4 "<}
void besh()
{
cout<<" 5 4 3 2 1 2 3 4 5 "<}
void olti()
{
cout<<" 6 5 4 3 2 1 2 3 4 5 6 "<}
void yetti()
{
cout<<" 7 6 5 4 3 2 1 2 3 4 5 6 7 "<}
void sakkiz()
{
cout<<" 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 "<}
void tuqqiz()
{
cout<<"9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9"<}
int main()
{
int n; cin>>n;
switch(n)
{
case 1: bir(); break;
case 2: bir(); ikki(); break;
case 3: bir(); ikki(); uch(); break;
case 4: bir(); ikki(); uch(); turt(); break;
case 5: bir(); ikki(); uch(); turt(); besh(); break;
case 6: bir(); ikki(); uch(); turt(); besh(); olti(); break;
case 7: bir(); ikki(); uch(); turt(); besh(); olti(); yetti(); break;
case 8: bir(); ikki(); uch(); turt(); besh(); olti(); yetti(); sakkiz(); break;
case 9: bir(); ikki(); uch(); turt(); besh(); olti(); yetti(); sakkiz(); tuqqiz(); break;
}
}
|
| |