當前位置:編程學習大全網 - 源碼下載 - Printf源代碼實現

Printf源代碼實現

# include & ltstdio.h & gt

# include & ltstring.h & gt

struct?學生{

intStudent _ ID

夏爾?名稱[12];

int?分數;

};

int?主要(無效){

int?I,j;

struct?學生?s[10];

作廢?排序(struct?學生?* p);

for(I = 0;我& lt10;i++){

Printf("請輸入%d學生的學號:\n ",I+1);

scanf("%d ",& amps[i]。學生_ ID);//在此接收標準輸入的地址。

while(getchar()!= ' \ n ');//這裏釋放輸入學號帶來的多余字符。

Printf("請輸入%d學生的姓名:\n ",I+1);

j = 0;

while((s[i])。name[j]=getchar())!='\n ')

j++;

s[i]。name[j]= ' \ 0 ';//這裏溢出。只需將最後壹個數字設置為' \0 '。

Printf("請輸入%d學生的成績:\n ",I+1);

scanf("%d ",& amps[i]。分數);//在此接收標準輸入的地址。

}

排序;//妳要排序,不然題就白做了。

for(I = 0;我& lt10;i++)

printf("%-6d%s\t%-6d\n ",s[i]。Student_ID,s[i]。姓名,s[i]。分數);//字符串輸出用指針,然後把格式做好。

回歸?0;

}

作廢?排序(struct?學生?*p){//問題需要排序?代碼邏輯是自己研究的。

int?I,j,flag

struct?學生?溫度;

for(I = 0;我& lt10;i++){

旗幟?=?我;

temp = p[I];

for(j = I+1;j & lt10;j++){

if(p[j].得分& ltp[i]。分數){

旗幟?=?j;

}

}

temp = p[flag];

p[flag]= p[I];

p[I]= temp;

}

}

  • 上一篇:對web前端開發的認識和理解,這個要怎麽回答
  • 下一篇:2023年過年發紅包最大方的幾大星座,快給他們拜個早年!?
  • copyright 2024編程學習大全網