Untitled

 avatar
unknown
c_cpp
23 days ago
3.3 kB
6
Indexable
// bai 1
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  int soNguyen;
  float soThuc;
  char kyTu;
  cout << "Nhap vao:\n";
  cin >> soNguyen >> soThuc >> kyTu;
  cout << fixed << setprecision(2) << (float)soNguyen + soThuc << endl;
  cout << (int)soThuc * soNguyen << endl;
  int c = (int)kyTu;
  cout << fixed << setprecision(2) << (c + soNguyen + soThuc) / 3 << endl;
  return 0;
}
// bai 2
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
  int x1, y1, x2, y2, x3, y3, x, y;
  cout << "Nhap toa do diem A\n";
  cin >> x1 >> y1;
  cout << "Nhap toa do diem B\n";
  cin >> x2 >> y2;
  cout << "Nhap toa do diem B\n";
  cin >> x3 >> x3;
  cout << "Nhap toa do diem P\n";
  cin >> x >> y;
  double dienTich = fabs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2;
  double dienTich1 = fabs(x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2)) / 2;
  double dienTich2 = fabs(x2 * (y3 - y) + x3 * (y - y2) + x * (y2 - y3)) / 2;
  double dienTich3 = fabs(x3 * (y1 - y) + x1 * (y - y3) + x * (y3 - y1)) / 2;
  double S = dienTich1 + dienTich2 + dienTich3;
  if (dienTich == S)
    cout << "Diem P nam trong tam giac ABC" << endl;
  else
    cout << "Diem P khong nam trong tam giac ABC" << endl;
  return 0;
}
// bai 3
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
  int h, p, s;
  cin >> h >> p >> s;
  if (h < 0 || h > 24 || p < 0 || p > 60 || s < 0 || s > 60)
  {
    cout << "Loi" << endl;
    return 0;
  }
  else
  {
    int H = h, P = p, S = s;
    if (s == 0)
    {
      S = 59;
      if (p == 0)
      {
        P = 59;
        if (h == 0)
        {
          H = 23;
        }
        else
        {
          H--;
        }
      }
      else
      {
        P--;
      }
    }
    else
    {
      S--;
    }
    int t = h, m = p, n = s;
    if (s == 59)
    {
      n = 0;
      if (p == 59)
      {
        m = 0;
        if (h == 23)
        {
          t = 0;
        }
        else
        {
          t++;
        }
      }
      else
      {
        m++;
      }
    }
    else
    {
      n++;
    }
    cout << setw(2) << setfill('0') << H << ":" << setw(2) << setfill('0') << P << ":" << setw(2) << setfill('0') << S << endl;
    cout << setw(2) << setfill('0') << h << ":" << setw(2) << setfill('0') << p << ":" << setw(2) << setfill('0') << s << endl;
    cout << setw(2) << setfill('0') << t << ":" << setw(2) << setfill('0') << m << ":" << setw(2) << setfill('0') << n << endl;
  }
}
// bai 4
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
  int soDien;
  cout << "Nhap so dien\n";
  cin >> soDien;
  long long thanhTien = 0;
  if (soDien <= 50)
    thanhTien = soDien * 1678;
  else if (soDien >= 51 && soDien <= 100)
    thanhTien = (soDien - 50) * 1734 + 50 * 1678;
  else if (soDien >= 101 && soDien <= 200)
    thanhTien = (soDien - 100) * 2014 + 50 * 1734 + 50 * 1678;
  else if (soDien >= 201 && soDien <= 300)
    thanhTien = (soDien - 200) * 2536 + 100 * 2014 + 50 * 1734 + 50 * 1678;
  else
    (soDien - 300) * 2927 + 1000 * 2536 + 100 * 2014 + 50 * 1734 + 50 * 1678;
  cout << thanhTien << endl;
}
Leave a Comment