Topshiriq 1-misol: if,for,switch-case qatnashgan ixtiyoriy dastur tuzing (10-ball)


Download 144.09 Kb.
Sana24.12.2022
Hajmi144.09 Kb.
#1061158
Bog'liq
MI

Topshiriq

1-misol: if,for,switch-case qatnashgan ixtiyoriy dastur tuzing (10-ball).


D (kun) va M (oy) sanasini ifodalovchi ikkita butun son berilgan. (Kabisa bo'lmagan yil sanasini o'z ichiga oladi). Berilgan sanani ifodalovchi dastur tuzing. Kabisa yili 366 kundan, kabisa yili 365 kundan iborat

Dastur kodi:

#include

#include

using namespace std;

int main()

{

int d, m;

cout << " sanani kiriting d="; cin>> d;

cout << "oyni tanlang m= "; cin>> m;

switch (m)

{

case 1: cout << d << "-" << "yanvar" << endl; break;

case 2: cout << d << "-" << "fevral" << endl; break;

case 3: cout << d << "-" << "mart" << endl; break;

case 4: cout << d << "-"<< "aprel" << endl; break;

case 5: cout << d << "_" << "may" << endl; break;

case 6: cout << d << "-" << "iyun" << endl; break;

case 7: cout << d << "_" << "iyul" << endl; break;

case 8: cout << d << "-" << "avgust" << endl; break;

case 9: cout << d << "_" << "sentabr" << endl; break;

case 10: cout << d << "_" << "oktabr" << endl; break;

case 11: cout << d << "-" << "noyabr" << endl; break;

case 12: cout << d << "-" << "dekabr" << endl; break;

default: cout << "xato" << endl; break;

}

return 0;

}

Natija:



2-misol:Ikki o’lchamli massivlarga doir ixtiyoriy dastur tuzing (10-ball).


Berilgan m, n va q butun sonlar va m butun sonlar to‘plami. m x n matritsa hosil qiling, uning birinchi ustunida kiritilgan m son bo‘lsin. Qolgan ustunlar q sonini oldingi ustunning satr elementining qiymatiga ko'paytirish orqali hosil bo'lsin. (Natija har bir satrda geometrik progressiyadir)


Dastur kodi:


#include
using namespace std;
int main()
{
int m, n, q, a[10] [10];
cout <<"Satrlar sonini kiriting \nm=";
cin >> m;
cout<<"Ustunlar sonini kiriting \nn=";
cin >> n;

cout <<"Geometrik prograssiya maxrajini kiriting\nq-"; cin >> q;
cout<<"m ta soni kiriting \n";
for (int i = 0; i < m; i++)
cin >> a[i][0];
for (int i = 0; i < m; i++)
for (int j=0;j a[i][j+1]= a[i][j]*q;
// matritsani jadval shaklida chiqarish
for (int i = 0; i < m; i++)
{
for (int j=0; j < n; j++)
cout << a[i][j] << " ";
cout<<"\n";
}
return 0;

}
Natija:





Download 144.09 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling