Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

請問要這個程式要如何把每人的年薪水排大小?(可以給些看法嗎)

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <conio.h>

int main(void)

{

int i,num=-1;

char keyin[10];

char ptr;

struct chname

{

char last[15];

char first[15];

};

struct data

{

int year;

int month;

int day;

};

struct money

{

int monthm;

int yearf;

};

struct person

{

struct chname name1;

struct data birth;

struct money all;

};

struct person p[3]={ {{"a","三風"},{1990,1,19},{3,6}},

{{"b","我行"},{1990,9,16},{4,8}},

{{"c","天正"},{1990,4,15},{5,9}}

};

for(i=0;i<3;i++)

{

printf("1.中文姓名 :%s %s\n",p[i].name1.last,p[i].name1.first);

printf("2.出生年份 :%d年\n",p[i].birth.year);

printf("3.出生月份 :%d月\n",p[i].birth.month);

printf("4.出生日期 :%d日\n",p[i].birth.day);

printf("5.月薪 :%d萬\n",p[i].all.monthm);

printf("6.年終獎金 :%d個月\n",p[i].all.yearf);

printf("\n\n");

}

getchar();

getchar();

return 0;

}

1 Answer

Rating
  • 1 decade ago
    Best Answer

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

    #include <conio.h>

    void bubble(int a[]);

    int main(void)

    {

    int i,j,num=-1;

    int order[3];

    char keyin[10];

    char ptr;

    struct chname

    {

    char last[15];

    char first[15];

    };

    struct data

    {

    int year;

    int month;

    int day;

    };

    struct money

    {

    int monthm;

    int yearf;

    };

    struct person

    {

    struct chname name1;

    struct data birth;

    struct money all;

    };

    struct person p[3]={ {{"a","三風"},{1990,1,19},{3,6}},

    {{"b","我行"},{1990,9,16},{4,8}},

    {{"c","天正"},{1990,4,15},{5,9}}

    };

    for(i=0;i<3;i++)

    {

    printf("1.中文姓名 :%s %s\n",p[i].name1.last,p[i].name1.first);

    printf("2.出生年份 :%d年\n",p[i].birth.year);

    printf("3.出生月份 :%d月\n",p[i].birth.month);

    printf("4.出生日期 :%d日\n",p[i].birth.day);

    printf("5.月薪 :%d萬\n",p[i].all.monthm);

    printf("6.年終獎金 :%d個月\n",p[i].all.yearf);

    order[i]=p[i].all.monthm*12*10000+p[i].all.monthm*10000*p[i].all.yearf; /*年薪加年終獎金*/

    }

    printf("\n");

    printf("年薪水排序結果(大->小):\n");

    for(j=0;j<3;j++)

    printf("%d ",order[j]);

    printf("\n\n");

    system("pause");

    return 0;

    }

    void bubble(int a[]) /*氣泡排序法*/

    {

    int i,j,temp;

    for(i=1;i<3;i++)

    for(j=0;j<(3-i);j++)

    if(a[j]<a[j+1])

    {

    temp=a[j];

    a[j]=a[j+1];

    a[j+1]=temp;

    }

    }

    不知道有沒有符合您要的~~

    Source(s): me
Still have questions? Get your answers by asking now.