By GokiSoft.com|
20:22 25/09/2023|
Lập Trình C
Bài tập - Quản lý hình chữ nhật - struct trong C - Lập trình C
1. Tạo 1 struct gồm các thuộc tính sau -> float : dientich, float chieudai, float chieurong
2. Tạo mảng list gồm 5 HCN
3. Nhập thông tin chiều dài và chiều rộng cho 5 HCN trên
4. Tính diện tích của từng HCN và lưu vào biến dientich tương ứng
5. Tính tổng diện tích 5 HCN trên
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Dao Thu Huyen [C2010G]](https://www.gravatar.com/avatar/5b36edefa31ea00344faf3dc52f2b8eb.jpg?s=80&d=mm&r=g)
Dao Thu Huyen
2020-12-23 03:45:19
#include <stdio.h>
typedef struct{
float dientich;
float chieudai;
float chieurong;
float tongdientich;
}Sum;
int main(void){
float dientich,chieudai,chieurong,tongdientich=0.0;
Sum tong ={dientich,chieudai,chieurong,tongdientich};
int hcn_list[5];
int i, sum=0;
for(i=0; i<5; i++){
printf("Nhap chieu dai HCN thu %d: ", i+1);
scanf("%f", &tong.chieudai);
printf("Nhap chieu rong HCN thu %d: ", i+1);
scanf("%f", &tong.chieurong);
tong.dientich= tong.chieudai*tong.chieurong;
printf("Dien tich HCN thu %d la: %.2f\n", i+1, tong.dientich);
tong.tongdientich+=tong.dientich;
} printf("Tong dien tich 5 HCN la: %.2f", tong.tongdientich);
}
![Đỗ Minh Tâm [community,C2010G]](https://www.gravatar.com/avatar/b2f111c1b0e4273177f902fd0c0f11ae.jpg?s=80&d=mm&r=g)
Đỗ Minh Tâm
2020-12-23 03:26:36
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct hinhchunhat_ST{
float chieudai,chieurong,dientich;
}hinhchunhat;
int main(int argc, char *argv[]){
struct hinhchunhat_ST;
hinhchunhat hinhchunhatList[5];
int a;
int sum=0;
for (a=0;a<5;a++){
printf("nhap vao hinh chu nhat thu:%d ",a+1);
printf("\nNhap chieu dai: ");
scanf("%f", &hinhchunhatList[a].chieudai);
printf("\nNhap chieu rong: ");
scanf("%f", &hinhchunhatList[a].chieurong);
printf("\nDien tich hinh chu nhat %d la: %f\n ",a+1,hinhchunhatList[a].dientich=(hinhchunhatList[a].chieudai)*(hinhchunhatList[a].chieurong));
sum +=hinhchunhatList[a].dientich;
}
printf("\nTong dien tich 5 HCN la: %d", sum);
}
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2020-09-28 03:19:31
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct HCN{
float dientich, chieudai, chieurong ;
}HCN;
int main(int argc, char *argv[]) {
HCN List[5];
int i;
float sum;
sum=0;
for (i=0;i<5;i++){
printf("\nNhap hinh chu nhat thu %d",i);
printf("\nNhap chieu dai:");
scanf("%f", &List[i].chieudai);
printf("\nNhap chieu rong: ");
scanf("%f", &List[i].chieurong);
printf("\nDien tich hinh chu nhat thu %d la: %f", i, List[i].dientich=List[i].chieudai*List[i].chieurong);
sum = sum+List[i].dientich;
}
printf("\nTong dien tich 5 hinh chu nhat: %f", sum);
return 0;
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-09-24 09:01:09
#include <stdio.h>
#include <stdlib.h>
typedef struct HCN_ST {
float dientich, chieudai, chieurong;
}hcn;
int main(int argc, char *argv[]) {
hcn list[5];
int i;
for(i=0;i<5;i++){
printf("\nNhap chieu dai hinh chu nhat thu %d: ", i+1); scanf("%f", &list[i].chieudai);
printf("\nNhap chieu rong hinh chu nhat thu %d: ", i+1); scanf("%f", &list[i].chieurong);
list[i].dientich = list[i].chieudai * list[i].chieurong;
printf("\nDien tich hinh chu nhat thu %d = %f", i+1, list[i].dientich);
}
float tongdientich = 0;
for(i=0;i<5;i++){
tongdientich = tongdientich + list[i].dientich;
}
printf("\nTong dien tich = %f", tongdientich);
return 0;
}
![Nguyễn Anh Vũ [T2008A]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2020-09-24 05:04:23
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bat dau code;
typedef struct hcn_st {
float a, b, s;
} Hcn;
int main(int argc, char *argv[]) {
Hcn Hcnlist[5];
int tong=0;
int i;
//nhap du lieu(Hcnlist);
int i;
for(i=0,i<5,i++){
printf("\nHinh chu nhat %d: ", i+1);
printf("\nNhap chieu dai cua hinh chu nhat: ");
scanf("%d", &Hcn[i].a);
printf("\nNhap chieu rong cua hinh chu nhat: ");
scanf("%d", &Hcn[i].b);
}
//dien tich Hcn(Hcnlist);
int i;
for(i=0,i<5,i++){
hcn[i].s =Hcn[i].a*hcn[i].b;
printf("\nDien tich hinh chu nhat %d = %d",i+1,Hcn[i].s);
}
//tong dien tich 5 Hcn(Hcnlist);
int i;
int tong=0;
for(i=0,i<5,i++){
tong+=Hcn[i].s;
}
printf("\nTong dien tich cua 5 hinh chu nhat = %d", tong);
//ket thuc coded;
return 0;
}
![Nguyên Phấn Đông [community]](https://www.gravatar.com/avatar/c9c4f8f79ce35b9224637b6cc5fbe5c4.jpg?s=80&d=mm&r=g)
Nguyên Phấn Đông
2020-09-24 02:49:13
#include<stdio.h>
#include<stdlib.h>
typedef struct HCN{
float s, d, r;
}HCN;
int main(){
HCN list[5];
for(int i=0;i<5;i++){
printf("\nnhap chieu dai: "); scanf("%f",&list[i].d);
printf("nhap chieu rong: "); scanf("%f",&list[i].r);
list[i].s= list[i].d* list[i].r;
printf("Dien tich HCN la: %f",list[i].s);
}
int sum;
sum =0;
for(int i=0;i<5;i++)(
sum=sum+ list[i].s);
printf("\ntong S: %f",sum);
return 0;
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2020-09-23 14:37:43
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct HCN_ST{
float s, d, r;
}HCN;
int main(int argc, char *argv[]) {
HCN List[5];
int i;
for(i = 0; i < 5; i++){
printf("\nNhap chieu dai =");
scanf("%f", &List[i].d);
printf("\nNhap chieu rong =");
scanf("%d", &List[i].r);
List[i].s = List[i].d * List[i].r;
printf("\nDien tich = %f", List[i].s);
}
float sum;
sum = 0;
for(i = 0; i < 5; i++){
sum = sum + List[5].s;
}printf("\nTong = %f", sum);
return 0;
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2020-09-23 13:00:49
typedef struct HCN{
float dai,rong;
float dt;
}HCN;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
HCN List[5];
int i;
for(i=0;i<5;i++) {
printf("\n hinh cn %d", i);
printf("\nNhap chieu dai: ");
scanf("%f" ,&List[i].dai);
printf("\nNhap chieu rong: ");
scanf("%f" ,&List[i].rong);
List[i].dt=List[i].dai*List[i].rong;
printf("\ndien tich= %f ",List[i].dt);}
float t=0;
for(i=0;i<5;i++){
t=t+List[i].dt;}
printf("\n tong = %f ",t);
return 0;
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2020-09-23 09:39:14
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct HCN_ST{
float s,a,b;
}HCN;
int main() {
HCN stdlist[5];
int i;
for(i=0;i<5;i++){
printf("\nNhap HCN thu %d:",i+1);
printf("\nNhap a:");
scanf("%f",&stdlist[i].a);
printf("\nNhap b:");
scanf("%f",&stdlist[i].b);
stdlist[i].s=stdlist[i].a*stdlist[i].b;
printf("\nDien tich HCN =%f",stdlist[i].a*stdlist[i].b);
}
float sum=0;
for(i=0;i<5;i++){
sum+=stdlist[i].s;
}
printf("\nDien tich =%f",sum);
return 0;
}
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2020-09-23 09:11:06
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct HCN {
int dt,d,r;
}HCN;
int main(int argc, char *argv[]) {
HCN c[5];
int i;
for(i=0;i<5;i++){
printf("\n hinh cn thu %d ",i);
printf("\n nhap chieu dai cua hinh ");
scanf("%d",&c[i].d);
printf("\n nhap chieu rong ");
scanf("%d",&c[i].r);
c[i].dt=c[i].d*c[i].r;
printf("dien tich cua hinh cn %d = %d ",i,c[i].dt);
}
int t=0;
for(i=0;i<5;i++){
t=t+c[i].dt;
}printf("\n tong dt 5 hinh cn = %d",t);
return 0;
}