當前位置:編程學習大全網 - 編程軟體 - c語言編程:輸入n個學生的數學成績,輸出平均分和最高分以及最高分所在的數組序號

c語言編程:輸入n個學生的數學成績,輸出平均分和最高分以及最高分所在的數組序號

//#include?"stdafx.h"//If?the?vc++6.0,?with?this?line.

#include?"stdio.h"

#include?"stdlib.h"

int?main(void){

int?n,i,max,sum,*pstu;

printf("How?many?studens?\nn=");

while(1){

if(scanf("%d",&n),n>0)

break;

printf("Error,?redo.?n?must?be?greater?than?0.\n");

}

if((pstu=(int?*)malloc(sizeof(int)*n))==NULL){

printf("Application?memory?failure...\n");

exit(0);

}

printf("Please?enter?%d?students?score...\n",n);

for(sum=max=i=0;i<n;i++){

scanf("%d",pstu+i);

sum+=pstu[i];

if(max<pstu[i])

max=pstu[i];

}

printf("The?average?is?%g\nThe?max?is?%d.?The?subscript:?",sum/(n+0.0),max);

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

if(max==pstu[i])

printf("%d?",i);

free(pstu);

printf("\n");

return?0;

}

  • 上一篇:半導體邏輯器件是什麽意思
  • 下一篇:什麽是才面向接口的編程 ? 常常看到壹些項目中 為每壹個類都寫個配套的接口 其用意到底在哪裏?
  • copyright 2024編程學習大全網