O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XOZAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Algoritmlarni loyihalash
1-6 labaratoriya ishlari
Bajardi:Abdullayev Bahriddin
Tekshirdi: Sabirov Karimjon
TOSHKENT 2022
1-ish.
#include
#include
using namespace std;
int main()
{
float a, b, c, x1, x2, discriminant, realPart, imaginaryPart;
cout << "Enter coeffitcients a, b and c: ";
cin >> a >> b >> c;
discriminant = b*b- 4*a*c;
if (discriminant > 0)
{
x1 = (-b + sqrt(discriminant))/(2*a);
x2 = ( -b - sqrt(discriminant))/(2*a);
cout << "Roots are real and different."<cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
else if (discriminant == 0)
{
cout << "Roots are real and same. " << endl;
x1 = -b/(2*a);
cout << "x1 = x2 = " << x1 << endl;
}
else if (discriminant < 0)
cout<<"yechim mavjud emas ";
}
2-ish.
#include
using namespace std;
#define SIZE 50 //Defining max size of array
int main()
{
int array[SIZE];
int i, max, min, size;
Input size of the array
cout<<"Enter size of the array: ";
cin>>size;
Input array elements
cout<<"\n Enter "<for(i=0; icin>>array[i];
Assume first element as maximum and minimum
max = array[0];
min = array[0];
Find maximum and minimum in all array elements.
for(i=1; i{
If current element is greater than max
if(array[i] > max)
max = array[i];
If current element is smaller than min
if(array[i] < min)
min = array[i];
}
Print maximum and minimum element
cout<<"\nMaximum element =" << max << "\n";
cout<<"Minimum element =" << min;
return 0;
}
3-ish.
#include
using namespace std;
int main()
{
int A[3][3]={{2,3,-1},{4,5,2},{-1,0,7}},B[3][3]={{-1,0,5},{0,1,3},{2,-2,4}};
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<}
cout<}
cout<for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<}
cout<}
cout<int C[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=2*(A[i][j]+B[i][j]);
cout<}
cout<}
cout<
int D[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
D[i][j]=2*B[i][j]-A[i][j];
cout<}
cout<}
cout<
int R[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
int sum1 = 0;
for(int k=0;k<3;k++)
{
sum1 += C[i][k] * D[k][j];
}
R[i][j] = sum1;
cout<}
cout<}
cout<
return 0;
}
5-6-ish.
def f(x:float) -> float:
return 2**x+5**x-3
#return 3*3**x + 4*x**3 - 12*x**2 - 5
# return 0.5*x+1-(x-2)**2
# return (x-3)*cos-1
def bisection(a, b):
if f(a) * f(b) >= 0:
print("Siz a va b ni xato kiritdingiz")
return
c = a
while (b - a) >= 0.01:
c = (a + b) / 2
if f(c) == 0.0:
break
if f(c) * f(a) < 0:
b = c
else:
a = c
print("Natija: ", "%.3f" % c)
a = -200
b = 300
bisection(a=a, b=b)
Do'stlaringiz bilan baham: |