วันจันทร์ที่ 29 มิถุนายน พ.ศ. 2552

การบ้าน"Structure"

struct date{
int day;
int month;
int year;
};
struct mobile{
char brand[20];
char modle[20];
char color[10];
int item;
float price;
struct date date1;
}mobile1;


ตัวอย่างการเขียนโปรแกรม
#include
#include
void main ()
{
struct date{
int day;
int month;
int year;
};
struct mobile{
char brand[20];
char modle[20];
char color[10];
int item;
float price;
struct date date1;
}mobile1;

strcpy(mobile1.brand,"nokia");
strcpy(mobile1.modle,"N72");
strcpy(mobile1.color,"black");
mobile1.item=1;
mobile1.price=7800;
mobile1.date1.day=17;
mobile1.date1.month=04;
mobile1.date1.year=2550;

printf("\t\t\tmobile\n\n");
printf("brand:%s\n\n",mobile1.brand);
printf("modle:%s\n\n",mobile1.modle);
printf("color:%s\n\n",mobile1.color);
printf("item:%d\n\n",mobile1.item);
printf("price:%f\n\n",mobile1.price);
printf("day:%d\n\n",mobile1.date1.day);
printf("month:%d\n\n",mobile1.date1.month);
printf("year:%d\n\n",mobile1.date1.year);
printf("\t\t\tend\n");

}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น