Created
December 10, 2023 17:02
-
-
Save nhandt64/7a1887ea6e0e516c49919477aee1d074 to your computer and use it in GitHub Desktop.
wtf bro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <conio.h> | |
#include <math.h> | |
void sapXep(float arr[], int n); | |
void inKetQua(float arr[], int n); | |
void prog1(); | |
void SaoChep(char *ChuoiNguon, char *ChuoiDich, int ViTri, int SoKyTu); | |
void prog2(); | |
void prog3(); | |
int main(){ | |
printf("BAI TAP CA NHAN GIUA KY\n"); | |
printf("DANG TRUNG NHAN - B2207483\n"); | |
printf("Bai tap so 3\n"); | |
printf("===========================\n"); | |
int p; | |
printf("Vui long chon chuong trinh con:\n"); | |
printf("1. Mang, sap xep mang va chen them phan tu\n"); | |
printf("2. Ham sao chep du lieu su dung chuoi duoi dang con tro ky tu\n"); | |
printf("3. Su dung kieu cau truc cho tam giac\n"); | |
printf("Lua chon: "); | |
scanf("%d", &p); | |
getchar(); | |
switch (p) { | |
case 1: | |
prog1(); | |
break; | |
case 2: | |
prog2(); | |
break; | |
case 3: | |
prog3(); | |
break; | |
default: | |
printf("Khong nhan dang duoc yeu cau, dang dung chuong trinh...\n"); | |
break; | |
} | |
return 0; | |
} | |
void sapXep(float arr[], int n){ | |
int i, j; | |
for (i = 0; i < n - 1; ++i) { | |
for (j = 0; j < n - i - 1; ++j) { | |
if (arr[j] < arr[j + 1]){ | |
float t = arr[j]; | |
arr[j] = arr[j + 1]; | |
arr[j + 1] = t; | |
} | |
} | |
} | |
} | |
void inKetQua(float arr[], int n){ | |
int i; | |
printf("Mang nhan duoc: ["); | |
for (i = 0; i < n; i++) { | |
if (i < n - 1){ | |
printf("%g, ", arr[i]); | |
} else { | |
printf("%g", arr[i]); | |
} | |
} | |
printf("]\n"); | |
sapXep(arr, n); | |
printf("Mang sau khi sap xep giam dan: ["); | |
for (i = 0; i < n; i++) { | |
if (i < n - 1){ | |
printf("%g, ", arr[i]); | |
} else { | |
printf("%g", arr[i]); | |
} | |
} | |
printf("]\n"); | |
} | |
void prog1(){ | |
int i, n; | |
float arr[100]; | |
printf("Mang co bao nhieu phan tu: "); | |
scanf(" %d", &n); | |
for (i = 0; i < n; ++i) { | |
printf("Nhap gia tri phan tu thu %d: ", i + 1); | |
scanf("%f", &arr[i]); | |
} | |
inKetQua(arr, n); | |
float ins; | |
printf("Nhap so can chen vao mang: "); | |
scanf("%f", &ins); | |
n++; | |
arr[n - 1] = ins; | |
inKetQua(arr, n); | |
} | |
void SaoChep(char *ChuoiNguon, char *ChuoiDich, int ViTri, int SoKyTu) { | |
int i; | |
while (ViTri > 1 && *ChuoiNguon != '\0') { | |
ChuoiNguon++; | |
ViTri--; | |
} | |
for (i = 0; i < SoKyTu && *ChuoiNguon != '\0'; i++) { | |
*ChuoiDich = *ChuoiNguon; | |
ChuoiNguon++; | |
ChuoiDich++; | |
} | |
*ChuoiDich = '\0'; | |
} | |
void prog2() { | |
char ChuoiNguon[100]; | |
char ChuoiDich[70]; | |
int ViTri, SoKyTu; | |
printf("Nhap chuoi nguon: "); | |
gets(ChuoiNguon); | |
printf("Nhap vi tri bat dau sao chep: "); | |
scanf("%d", &ViTri); | |
printf("Nhap so ky tu can sao chep: "); | |
scanf("%d", &SoKyTu); | |
getchar(); | |
SaoChep(ChuoiNguon, ChuoiDich, ViTri, SoKyTu); | |
printf("Ket qua chuoi dich: %s\n", ChuoiDich); | |
} | |
typedef struct{ | |
float canhA; | |
float canhB; | |
float canhC; | |
} tamGiac; | |
void prog3(){ | |
tamGiac TG; | |
printf("Nhap do dai canh a: "); | |
scanf("%f", &TG.canhA); | |
printf("Nhap do dai canh b: "); | |
scanf("%f", &TG.canhB); | |
printf("Nhap do dai canh c: "); | |
scanf("%f", &TG.canhC); | |
getchar(); | |
if (TG.canhA + TG.canhB > TG.canhC && TG.canhA + TG.canhC > TG.canhB && TG.canhB + TG.canhC > TG.canhA){ | |
float chuVi = TG.canhA + TG.canhB + TG.canhC; | |
float p = chuVi / 2; | |
float dienTich = sqrt(p * (p - TG.canhA)*(p - TG.canhB)*(p - TG.canhC)); | |
printf("Chu vi cua tam giac la: %.2f\n", chuVi); | |
printf("Dien tich cua tam giac la: %.2f ", dienTich); | |
} else{ | |
printf("Ba do dai nay khong the tao nen mot tam giac!\n"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment