12 ta raqam bilan oylar berilgan berilgan oylarni qaysi fasilda ekanligni chiqaradigan dastur tuzing


Download 479.19 Kb.
Sana26.12.2022
Hajmi479.19 Kb.
#1067311
Bog'liq
Mustaqil ish nomalum


12 ta raqam bilan oylar berilgan berilgan oylarni qaysi fasilda ekanligni chiqaradigan dastur tuzing
Dastur kodi:
#include
#include
using namespace std;
int main()
{
int n;
cout<<" n = ";
cin>>n;

switch (n){


case 12:cout<<"dekabr ";break;
case 1:cout<<"yanvar ";break;
case 2:cout<<"fevral ";break;
case 3:cout<<"mart "; break;
case 4:cout<<"aprel ";break;
case 5:cout<<"may ";break;
case 6:cout<<"iyun ";break;
case 7:cout<<"iyul ";break;
case 8:cout<<"avgust ";break;
case 9:cout<<"sentabr ";break;
case 10:cout<<"oktabr ";break;
case 11:cout<<"noyabr ";break;
}
switch (n){
case 12:cout<<"qish fasliga to?g?ri keladi";break;
case 1:cout<<"qish fasliga to?g?ri keladi";break;
case 2:cout<<"qish fasliga to?g?ri keladi";break;
case 3:cout<<"bahor fasliga to?g?ri keladi"; break;
case 4:cout<<"bahor fasliga to?g?ri keladi";break;
case 5:cout<<"bahor fasliga to?g?ri keladi";break;
case 6:cout<<"yoz fasliga to?g?ri keladi";break;
case 7:cout<<"yoz fasliga to?g?ri keladi";break;
case 8:cout<<"yoz fasliga to?g?ri keladi";break;
case 9:cout<<"kuz fasliga to?g?ri keladi";break;
case 10:cout<<"kuz fasliga to?g?ri keladi";break;
case 11:cout<<"kuz fasliga to?g?ri keladi";break;
default :cout<<"bunday oy mavjud emas";}
return 0;
}
Natija:

m x m, matritsaning bosh diagonali elementlari yig‘indisini hosil qiluvchi dastur tuzing.
Dastur kodi:
#include
#include
using namespace std;
void matrix_print (int **a, int m)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < m; j++)
{
cout << a[i][j] << "\t";
} cout << "\n";
}
}
int main()
{
int m,**a;
cout << "Kvadrat matritsaning o'lchamini kiriting\nm="; cin>> m;
a= new int * [m];
for (int i = 0; i < m; i++)
a[i]= new int [m];
cout <<"Massiv elementlarini kiriting \n";
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++)
cin>> a[i][j];
cout << "Kiritilgan matritsa\n";
matrix_print (a, m);
int sum = 0;
for (int i = 0; i < m; i++)
sum += a[i] [i];
cout << "Asosiy dioganal elementlari yig'indisi=" << sum << endl;
for (int i = 0; i < m; i++)
delete []a[i];
delete []a;
return 0;
}
Natija:

Download 479.19 Kb.

Do'stlaringiz bilan baham:




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