Algoritmni loyihalash


Download 0.58 Mb.
bet5/5
Sana08.01.2022
Hajmi0.58 Mb.
#253531
1   2   3   4   5
Bog'liq
A l 2-topshiriq

Kirish ma'lumotlari

n natural son berilgan. A[n][n] massiv berilgan.



Chiquvchi ma’lumotlar

Har bir satrdan eng kata elementlarni chiqaring



#include

#include

using namespace std;

void matrix_print(int a[10][10], int n)

{

for (int i = 0; i < n; i++)

{

for (int j = 0; j < n; j++)

{

cout << a[i][j] << "\t";

}

cout << "\n";

}

}

int satr_max(int a[], int n)

{

int max = a[0];

for (int i = 1; i < n; i++)

if (max < a[i]) max = a[i];

return max;

}

int main()

{

int n, a[10][10];

cout << "Satrlar sonini kiriting \nn="; cin >> n;

cout <<"Massiv elementlarini kiriting \n";

for (int i = 0; i < n; i++)

for (int j = 0; j < n; j++)

cin >> a[i][j];

cout << "Kiritilgan matritsa\n";

matrix_print(a, n);

for (int i = 0; i < n; i++)

{

cout << i << "-satrning eng kattasi=" <<

satr_max(&a[i][0], n);

cout << endl;

}

return 0;

system ("pause");

}



2-masala.

Quyidagi funksiyani to’rtburchaklar, Trapetsiya va Simpson formulalari yordamida taqribiy hisoblash dasturini tuzing



#include

#include

using namespace std;

double funk(double x)

{

return (sin(x)/(1+x*x));

}

int main()

{

double a,b,S=0, xa;

int n=10;

cout<<"integral chegarasini kiriting"<

cin>>a>>b;

xa=a+0.1;

while (xa

{

S+=funk(xa);

xa+=0.1;

}

S*=fabs(b-a)/n;

cout << S;

return 0; }



  1. Ketma-ketlikning yig’indisini toping ; Sikl takrorlanishi . Algoritm samaradorligini baholang.

#include



using namespace std;



int main(){



double s=0,n;



for(double i=1;i<=300;i++)

{

if((1/i)-(1/(i+1))>0.0001)

s+=1/i;

}

cout<

}



  1. 2 ta kvadrat matritsa berilgan. Ularning yig’indisini toppish algoritmini toping va uni samaradorligini baholang.

#include

using namespace std

int main()

{

int m, n, c, d, first[100][100], second[100][100], sum[100][100];

cout << "Matritsa satr va ustunlar sonini kiriting:\n";

cin >> n;

cout << "Birinchi matritsa elementlarini kiriting\n";



for (c = 0; c < n; c++)

for (d = 0; d < n; d++)

cin >> first[c][d];

cout << "Ikkinchi matritsa elementlarini kiriting\n";

for (c = 0; c < n; c++)

for (d = 0; d < n; d++)

cin >> second[c][d];

for (c = 0; c < n; c++)

for (d = 0; d < n; d++)

sum[c][d] = first[c][d] + second[c][d];

cout << "Matritsalar yig'indisi:\n";

for (c = 0; c < n; c++)

{

for (d = 0; d < n; d++)

cout << sum[c][d] << "\t";

cout << endl;

}

return 0;

}

3. n o’lchamli kvadrat matritsa berilgan. Uning teskari matritsasini toppish algoritmini toping va uni samaradorligini baholang.



#include



using namespace std;



int main(){

int mat[3][3], i, j;

float determinant = 0;



cout<<"Matritsa elementlarini kiriting:\n";

for(i = 0; i < 3; i++)

for(j = 0; j < 3; j++)

cin>>mat[i][j];



printf("\nMatritsa Joylashuvi:");

for(i = 0; i < 3; i++){

cout<<"\n";



for(j = 0; j < 3; j++)

cout<
}





for(i = 0; i < 3; i++)

determinant = determinant + (mat[0][i] * (mat[1][(i+1)%3] * mat[2][(i+2)%3] - mat[1][(i+2)%3] * mat[2][(i+1)%3]));





cout<<"\n\nteskari matritsa: \n";

for(i = 0; i < 3; i++){

for(j = 0; j < 3; j++)

cout<<((mat[(j+1)%3][(i+1)%3] * mat[(j+2)%3][(i+2)%3]) - (mat[(j+1)%3][(i+2)%3] * mat[(j+2)%3][(i+1)%3]))/ determinant<<"\t";



cout<<"\n";

}



return 0;

}





Download 0.58 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




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