KTLT 1
B1:
Code:
#include <bits/stdc++.h>
using namespace std;
void daonguoc(int n)
{
int t = n % 10;
cout<<t;
n = n / 10;
}
int main()
{
int n;
cout<<"Nhap:";
cin>>n;
long long b[100000] , x = 0 , sum = 0 , count = 0;
int k = n;
while(n != 0)
{
int t = n % 10;
b[x++] = t;
sum += t;
count++;
n = n / 10;
}
cout<<k<<" co "<<count<<" chu so"<<endl;
cout<<"Chu so cuoi cung la:"<<b[0]<<endl;
cout<<"Chu so dau tien la:"<<b[count-1]<<endl;
cout<<"Tong cac chu so la:"<<sum<<endl;
cout<<"So dao nguoc la:";
daonguoc(k);
return 0;
}
B2:
Code:
#include <bits/stdc++.h>
using namespace std;
double range(int x1 , int y1 , int x2 , int y2)
{
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double acreage(int a , int b , int c)
{
if(a+b > c && a + c > b && b + c > a)
return sqrt(((a+b+c)/2)*(((a+b+c)/2)-a)*(((a+b+c)/2)-b)*(((a+b+c)/2)-c));
}
double check_the_coefficient(int a1 , int c1 , int a2 , int c2 , int xm , int ym)
{
double d = a1*1 - a2*1;
double dx = c1*1 - c2*1;
double dy = a1*c2 - a2*c1;
double a = dx/d;
double b = dy/d;
//y = ax + b
double y = a*xm + b - ym;
return y;
}
int main()
{
int x[4],y[4];
for(int i = 0 ; i < 4 ; i++)
cin>>x[i]>>y[i];
int xa = x[0] , ya = y[0];
int xb = x[1] , yb = y[1];
int xc = x[2] , yc = y[2];
int xm = x[3] , ym = y[3];
double AB = range(x[0] , y[0] , x[1] , y[1]);
double AC = range(x[0] , y[0] , x[2] , y[2]);
double BC = range(x[1] , y[1] , x[2] , y[2]);
double AM = range(x[0] , y[0] , x[3] , y[3]);
double BM = range(x[1] , y[1] , x[3] , y[3]);
double CM = range(x[2] , y[2] , x[3] , y[3]);
double S_abc = acreage(AB , AC , BC);
double S_abm = acreage(AB , BM , AM);
double S_acm = acreage(AC , CM , AM);
double S_bcm = acreage(BC , CM , BM);
double Check_sum_S = S_abm + S_acm + S_bcm;
if(Check_sum_S == S_abc)
cout<<"M in the side of the triangle ABC";
int k1 = check_the_coefficient(x[0],y[0],x[1],y[1],x[3],y[3]);
int k2 = check_the_coefficient(x[0],y[0],x[2],y[2],x[3],y[3]);
int k3 = check_the_coefficient(x[2],y[2],x[1],y[1],x[3],y[3]);
if(k1 == 0 || k2 == 0 || k3 == 0)
cout<<"M is on the side of the triangle ABC";
return 0;
}
B3:
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
// 1 phut = pi / 10800
// 1 PI = 180 do
int n;
cout<<"Nhap so do x cua goc (phut):";
cin>>n;
double doo = (double)(n*180) / 10800;
if(doo > 0 && doo < 90)
cout<<"x thuoc goc phan tu thu 1"<<endl;
if(doo > 90 && doo < 180)
cout<<"x thuoc goc phan tu thu 2"<<endl;
if(doo > 180 && doo < 270)
cout<<"x thuoc goc phan tu thu 3"<<endl;
if(doo > 270 && doo < 360)
cout<<"x thuoc goc phan tu thu 4"<<endl;
cout<<"cos(x) = "<<cos((n*(3.14/10800)));
return 0;
}
B4:
Code:
#include <bits/stdc++.h>
using namespace std;
void ROUND(double number , int k)
{
if(k == 0)
cout<<fixed<<setprecision(0)<<number;
if(k > 0)
cout<<fixed<<setprecision(k)<<number;
if(k < 0)
{
int z = number,i = 0,s;
while(z != 0)
{
int t = z % 10;
i++;
z = z / 10;
if(i == abs(k))
{
if(number > 0)
{
if(t >= 5)
{
for(int j = 1 ; j <= abs(k) ; j++)
s = (z + 1)*pow(10,i);
break;
}
if(t < 5 && t >= 0)
{
for(int j = 1 ; j <= abs(k) ; j++)
s = (z % 10)*pow(10,i);
break;
}
}
else
{
if(abs(t) >= 5)
{
for(int j = 1 ; j <= abs(k) ; j++)
s = (z - 1)*pow(10,i);
break;
}
if(abs(t) < 5 && abs(t) >= 0)
{
for(int j = 1 ; j <= abs(k) ; j++)
s = (z % 10)*pow(10,i);
break;
}
}
}
}
cout<<s;
}
}
int main()
{
double number;
int num_digits;
cout<<"Nhap so thuc x:";
cin>>number;
cout<<"Do chinh xac:";
cin>>num_digits;
ROUND(number,num_digits);
return 0;
}