HKI - LTCB Tuần 7
Bài 1:
#include<stdio.h>
#include<math.h>
typedef struct PhanSo{
int tu, mau;
};
void nhap(PhanSo &ps);
void xuat(PhanSo &ps);
void chuanhoa(PhanSo &ps);
int ucln(int a, int b);
void rutgon(PhanSo &ps);
void xuat(PhanSo &ps);
int main(){
PhanSo ps1, ps2;
printf("NHAP PHAN SO A\n"); nhap(ps1);
printf("NHAP PHAN SO B\n"); nhap(ps2);
printf("XUAT A: "); chuanhoa(ps1); rutgon(ps1); xuat(ps1);
return 0;
}
void nhap(PhanSo &ps){
printf("Nhap Tu: "); scanf("%i", &ps.tu);
printf("Nhap Mau: "); scanf("%i", &ps.mau);
}
void chuanhoa(PhanSo &ps){
if(ps.mau < 0){
ps.tu= -ps.tu;
ps.mau= abs(ps.mau);
}
}
int ucln(int a, int b){
a= abs(a); b= abs(b);
while(b!=0){
if(a > b) a-= b;
else b-= a;
}
return a;
}
void rutgon(PhanSo &ps){
int t= ucln(ps.tu,ps.mau);
ps.tu= ps.tu/t;
ps.mau= ps.mau/t;
}
void xuat(PhanSo &ps){
printf("%i / %i", ps.tu,ps.mau);
}
/*
Ten: Hoang Minh Tuan
Lop: GS19TH1
*/
#include<stdio.h>
#include<math.h>
typedef struct Elip{
int x, y, r1, r2;
};
void nhap(Elip &a);
float chuvi(Elip &a);
float dientich(Elip &a);
void xuat(Elip a);
int main(){
Elip a;
printf("====================== NHAP =================\n"); nhap(a);
printf("====================== XUAT =================\n"); xuat(a);
return 0;
}
void nhap(Elip &a){
printf("Nhap X= "); scanf("%i", &a.x);
printf("Nhap Y= "); scanf("%i", &a.y);
printf("Nhap R1= "); scanf("%i", &a.r1);
printf("Nhap R2= "); scanf("%i", &a.r2);
}
float chuvi(Elip &a){
float cv;
cv= 2*3.14*sqrt(((pow(a.r1,2))+(a.r2,2))/2);
return cv;
}
float dientich(Elip &a){
float dt;
dt= 3.14*a.r1*a.r2;
return dt;
}
void xuat(Elip a){
printf("X= %i\nY= %i\nR1= %i\nR2= %i\n", a.x ,a.y ,a.r1, a.r2);
printf("Chu Vi= %.2f", chuvi(a));
printf("\nDien Tich= %.2f", dientich(a));
}
/*
Ten: Hoang Minh Tuan
Lop: GS19TH1
*/
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define max 100
typedef struct Diem{
int x,y;
};
void nhap(Diem &a, Diem &b);
void xuat(Diem a, Diem b);
void khoangcach(Diem &a, Diem &b);
void truchoanh(Diem &a, Diem &b);
void tructung(Diem &a, Diem &b);
int main(){
Diem a, b; int n;
printf("==================== NHAP ====================\n"); nhap(a,b);
printf("\n================= XUAT ======================\n\n"); xuat(a,b);
printf("\n================= KHOANG CACH ==================\n\n"); khoangcach(a,b);
printf("\n================= KIEM TRA =================="); truchoanh(a,b); tructung(a,b);
return 0;
}
void nhap(Diem &a, Diem &b){
printf("Nhap Diem A: \n");
printf("x1= "); scanf("%i", &a.x);
printf("y1= "); scanf("%i", &a.y);
printf("Nhap Diem B:\n");
printf("x2= "); scanf("%i", &b.x);
printf("y2= "); scanf("%i", &b.y);
}
void xuat(Diem a, Diem b){
printf("Diem A: ( %i , %i )", a.x,a.y);
printf("\nDiem B: ( %i , %i )", b.x, b.y);
}
void khoangcach(Diem &a, Diem &b){
float kc;
kc= sqrt((pow(a.x - b.x , 2)) + (pow(a.y - b.y , 2)));
printf("KHOANG CACH AB= %.2f", kc);
}
void truchoanh(Diem &a, Diem &b){
if(a.y == 0) printf("\nDiem A Nam Tren Truc Hoanh");
if(b.y == 0) printf("\nDiem B Nam Tren Truc Hoanh");
else printf("\nKhong Diem Nao Nam Tren Truc Hoanh");
}
void tructung(Diem &a, Diem &b){
if(a.x == 0) printf("\nDiem A Nam Tren Truc Tung");
if(b.x == 0) printf("\nDIem B Nam Tren Truc Tung");
else printf("\nKhong Diem Nao Nam Tren Truc Tung");
}
No Comment to " HKI - LTCB Tuần 7 "