O`ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Dasturlash fani bo`yicha
3-Dasturlash Labaratoriya ishi
220-21-guruh
Bajardi: Karimov D.
Tekshirdi: Dualetov A.
Toshkent -2021
Variant № 11.
1-topshiriq.
a) Berilgan sonni factorialini hisoblaydigan funksiya yarating. Ushbu funksiya yordamida a,b,c funksiyalarini factorialini hosil qiling.
#include using namespace std; int factorial(int n)
{ if (n == 0) return 1;
return n * factorial(n - 1);
} int main()
{
int n;
cout << "Sonni kiriitng: n = "; cin >> n;
cout << "Kiritilgan sonning Faktoriali: " << factorial(n) << endl; return 0;
}
b) Palindrom funksiyasini hosil qiling. Ushbu funksiya yordamida a,b,c sonlarini palindromlikka tekshiring
#include using namespace std;
bool polindrom(int n) {
int m = n; int r=0;
while(n>0) { r = r*10 + n%10; n=n/10;
}
if(m == r) return true; else return false;
} int main() {
int n;
cout << "Sonni kiriitng: n = "; cin >> n;
cout << "Kiritilgan son polindrommi ?" << endl;
if(polindrom(n)) cout << "Ha" << endl; else cout << "Yo`q" << endl;
return 0;
}
2-topshiriq.
n ta elementdan tashkil topgan massiv berilgan.Bu massivning eng katta va eng kichik elementlari yig’indisi hisoblansin. (Ko’rsatkichlardan foydalaning)
#include using namespace std;
void findMax(int arr[], int n, int** pToMax) {
if (n <= 0) return;
*pToMax = arr;
for (int i = 1; i < n; i++)
{ if (arr[i] > *(*pToMax)) {
*pToMax = arr + i;
}
}
} void findMin(int arr[], int n, int** pToMax) {
if (n <= 0) return;
*pToMax = arr;
for (int i = 1; i < n; i++)
{ if (arr[i] < *(*pToMax)) { *pToMax = arr + i;
}
}
} int main() {
int n; int* ptrMax; int* ptrMin;
cout << "Massiv elementlari sonini kiriting n = ";
cin >> n;
int arr[n];
cout << "Massiv elementlarini kiriting: " << endl; for(int i = 0; i< n; i++) { cout << "arr [" << i << "] = " ; cin >> arr[i];
}
findMax(arr, n, &ptrMax); findMin(arr, n, &ptrMin);
cout << "\nMassivdegi eng katta element: " << *ptrMax << endl;
cout << "Massivdegi eng kichik element: " << *ptrMin << endl;
cout << "Eng katta element va eng kichik element yig`indisi:
" << *ptrMax + *ptrMin << endl; return 0;
}
3-topshiriq.
Elementlari bir-biriga teng bo‘lmagan haqiqiy turdagi 7- tartibli kvadrat matritsa berilgan. Eng katta elementi joylashgan satrning eng kichik elementi joylashgan ustunga ko‘paytmasi topilsin.
#include using namespace std;
int minElementIndex(int arr[10][10],int m,int n) {
int j = 0, i; int min = arr[0][0]; int res[m];
while (j < m)
{ for ( i = 0; i < n; i++) { if (min > arr[i][j]) { min = arr[i][j];
}
}
res[j] = min; min = arr[0][j]; j++; }
int minC = res[0]; for(int i = 0; i < n; i++) { if(minC > res[i]) {
minC = i;
}
}
return minC;
}
int main()
{ int m,n; printf("Matritsa tartibini kiriting: "); cin >> n;
m = n;
int arr[10][10];
cout << "\nMatritsa elementlarini kiriting: \n";
for(int i=0;i
for(int j=0;j
}
}
cout << "\nMatritsa : \n";
for(int i=0;i
{
for(int j=0;j
{
cout << arr[i][j] << "\t";
}
cout << endl;
}
int i = 0, j; int max = 0; int res[m]; int maxR = 0;
while (i < n)
{
for ( j = 0; j < m; j++)
{ if (arr[j][i] > max)
{ max = arr[j][i];
}
}
res[i] = max; max = 0; i++;
} for(int i = 0; i < n; i++)
{
if(maxR < res[i]) maxR = i;
}
int minC = minElementIndex(arr, m, n);
cout << "Eng katta elementi joylashgan satrning eng kichik elementi joylashgan ustunga ko'paytmasi : " << (maxR+1)*(minC+1) << endl;
return 0;
}
Do'stlaringiz bilan baham: |