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;
}