Tashkent university of information technologies named after muhammad al-khorezmi



Yüklə 103,43 Kb.
tarix19.04.2023
ölçüsü103,43 Kb.
#100540
1-Laboratoriya





TASHKENT UNIVERSITY OF INFORMATION TECHNOLOGIES NAMED AFTER MUHAMMAD AL-KHOREZMI
1-LABORATORY WORK
Subject: Algorithm design
Group: CAL401-L1
Done by: Abdullayev Shoxrux
Checked by: Sabirov Karimjon

Toshkent-2022
No. 1: Make an algorithm (flowchart) and a program for determining the roots of a quadratic equation.
#include
#include
using namespace std;
int main()
{
float a,b,c,x1,x2,disc;
cout<<"Koeffitsiyentlarni kiriting - ";
cin>>a>>b>>c;
disc = b*b-4*a*c;
if (disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
cout<<"Ildizlari mavjud:"< cout<<"x1 = "< cout<<"x2 = "< }
else
if(disc==0)
{
cout<<"Ildizi bitta:"< x1=-b/(2*a);
cout<<"x1=x2="< else
{
cout<<"Ildizlari mavjud emas!"<return 0;
}

2: Make an algorithm (flowchart) and a program to determine the minimum element of an array.
#include
using namespace std;
int main()
{
int a[]={2,3,1,10,8,2};
int min=a[0],max=a[0];
cout<<"Massiv elementlari:";
for(int k=0; k<6; k++)
{
cout<<" "< }
cout< for(int i=0; i<6; i++)
if(a[i] {
min=a[i];
}
cout<<"Minimal = "< cout< for(int j=0; j<6; j++)
if(a[j]>max)
{
max=a[j];
}
cout<<"Maksimal = "< return 0;
}



No. 3:
Make an algorithm (flowchart) and a program for exercuting operations on matrices
#include
using namespace std;
int main()
{
int n =3, m = 3;
int a[n][m] = { { 4, 5,-2 }, { 3, -1,0},{4,2,7} };
int b[n][m] = { { 2, 1,-1 }, { 0, 1,3 },{5,7,3} };
int i, j, k,g[n][m],t[n][m],e[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
g[i][j] = a[i][j] + 2*(b[i][j]);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
t[i][j] = 0;
for (k = 0; k < n; k++)
t[i][j] +=g[i][k]*b[k][j];
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
e[i][j] =3*(a[i][j])- t[i][j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << e[i][j] << " ";
cout << endl;
}
return 0;
}

No. 4: Make an algorithm (flowchart) and a program for calculating methods of approximate integration
#include
#include
using namespace std;
int main()
{double a,b,n,h,S=0;
cout << "a ni kiriting a=";cin>>a;
cout << "b ni kiriting b=";cin>>b;
cout << "n ni kiriting n=";cin>>n;
h=(b-a)/n;
cout << "h=" << h << endl;
for(int i=1;i<=n;i++)
{
S+=sqrt(0.5*(a+i*h)+2)/(sqrt(2*(a+i*h)*(a+i*h)+1)+0.8);
}
cout<<"S="<return 0;
}

5-6: Make an algorithm (flow diagram) and a program for solving nonlinear equations


#include
#include
#include
using namespace std;
double f(double x);
double f(double x)
{
double a=pow(x,3)-x-11.0;
return a;
}
int main()
{
cout.precision(4);
cout.setf(ios::fixed);
double a,b,c,e,fa,fb,fc;
a:cout<<"oraliqni kiriting:\na=";
cin>>a;
cout<<"\nb=";
cin>>b;
cout<<"\nAniqlilik darajasi"<cin>>e;
if (f(a)*f(b)>0)
{
goto a;
}
else
{
while (fabs(a-b)>=e)
{
c=(a+b)/2.0;
fa=f(a);
fb=f(b);
fc=f(c);
cout<<"a="<break;
}
if (fa*fc>0)
{
a=c;
}
else if (fa*fc<0)
{
b=c;
}
}
}
cout<<"Tenglama ildizi : "<return 0;
}

#include


using namespace std;
float f(float x)
{
float f = pow(x, 4) - 18*pow(x,2) +6;
return f;
}
void secant(float x1, float x2, float E)
{
float n = 0, xm, x0, c;
if (f(x1) * f(x2) < 0) {
do {
x0 = (x1 * f(x2) - x2 * f(x1)) / (f(x2) - f(x1));
c = f(x1) * f(x0);
x1 = x2;
x2 = x0;
n++;
if (c == 0)
break;
xm = (x1 * f(x2) - x2 * f(x1)) / (f(x2) - f(x1));
} while (fabs(xm - x0) >= E);
cout << "berilgan tenglama ildizi=" << x0 << endl;
cout << "qadamlar soni = " << n << endl;
} else
cout << "bu oraliqda yechim topilmadi";
}
// Driver code
int main()
{
// initializing the values
float x1, x2 , E = 0.0001;
cout<<"Oraliqni kiriting x1=";
cin>>x1;
cout<<"Oraliqni kiriting x2=";
cin>>x2;
secant(x1, x2, E);
return 0;
}

Yüklə 103,43 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin