Untitled

 avatar
unknown
plain_text
a month ago
3.3 kB
10
Indexable
//1
#include<iostream>

using namespace std;
//Ham nhap
float nhap()
{
    float x;
    cin >> x;
    return x;
}
// ham max
float MAX(float a, float b, float c)
{
    float soLon = a;
    if (b > soLon)
    {
        soLon = b;
    }
    if (c > soLon)
    {
        soLon = c;
    }
    return soLon;
}
//ham min
float MIN(float a, float b, float c)
{
    float soNho = a;
    if (b < soNho)
    {
        soNho = b;
    }
    if (c < soNho)
    {
        soNho = c;
    }
    return soNho;
}
// ham swap
float Swap(float n)
{
    int a = int (n);
    int hangTram = (a / 100) % 10;
    int hangChuc = (a / 10) % 10;
    int hangDv = a % 10;
    return hangDv * 100 + hangChuc * 10 + hangTram;
}

int main ()
{
    cin.tie(0),cout.tie(0)->sync_with_stdio(false);
    float a , b , c;
    a = nhap();
    b = nhap();
    c = nhap();
    float maxx = MAX(a, b ,c);
    float minn = MIN(a , b , c);
    cout << "MAX = " << maxx << " " << "MIN = " << minn << endl;

    float d = nhap();
    float e = nhap();
    float max2 = MAX (maxx , d , e);
    float min2 = MIN (minn , d, e );
    cout << "MAX = " << max2 << " " << "MIN = " << min2 << endl;

    if (max2 > 99 && max2 < 1000 && (int(max2) % 10) != 0)
    {
        cout << Swap(max2) << endl;
    }
    if (min2 > 99 && min2 < 1000 && (int (min2) % 10) != 0)
    {
        cout << Swap(min2) << endl;
    }
    return 0;
}

//2
#include<iostream>
#include<cmath>
using namespace std;

bool nguyenTo(int n) // hàm kiểm tra số nguyên tố
{
    for (int i = 2 ; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return n > 1;
}
int main ()
{
    cin.tie(0),cout.tie(0)->sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        if(nguyenTo(i))
        {
            cout << i << " ";
        }
    }
    return 0;
}

//3
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

double tong(double x , int n)
{
    if (n > 2)
    {
        double sum = sqrt(2024);
        double tmp = x + 1;
        for (int i = 1 ; i<= n ; i++)
        {
            sum += pow(tmp, i);
        }
        return sum;
    }
    else 
    {
        return abs(n * x);
    }
}

int main()
{
    double x;
    int n;
    cin >> x >> n;
    cout << fixed << setprecision(2) << tong(x , n) << endl;
    return 0;
}

//4
#include<iostream>
#include<iomanip>
using namespace std;

void giaiHe (double a, double b, double c, double d, double e , double f)
{
    double x , y;
    double denta = a * e - b * d;
    double dentaX = c * e - b * f;
    double dentaY = a * f - d * c;
    if ( denta != 0)
    {
        x = (dentaX) / (denta);
        y = (dentaY) / (denta);
        cout << "x = "  << x  << endl;
        cout << "y = "  << y  << endl;
    }
    else if (denta == 0 && dentaX == 0 && dentaY == 0 )
    {
        cout << " He phuong trinh vo so nghiem" << endl;
    }
    else 
    {
        cout << "He phuong trinh vo nghiem" << endl;
    }
}
int main()
{
    double a , b , c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    cout << "He phuong trinh:" << endl;
    cout << "|" << a << "x + " << b << "y = " << c << "\n" << "{\n" << "|" << d << "x + " << e << "y = " << f << "\n" << "==>\n";
    giaiHe(a , b , c, d, e, f);
    return 0;
}

Leave a Comment