當前位置:編程學習大全網 - 編程軟體 - 二維數組輸入

二維數組輸入

//vc6下編譯,運行成功,並達到題目效果

//程序如下:

#include<stdio.h>

int main()

{

int i,j;//用於for循環

int num,searchn;//num輸入的數字,searchn表示需要查找的學號

int student[8][7];//根據題目使用二維數組,***8名學生,7(表示的是1個學號+6個成績)

//輸入8個學生的成績,輸入時,成績用空格隔開,輸入好壹個學生後按回車鍵換行輸入下壹個學生的成績

//格式是:學號 成績1 成績2 成績3 成績4 成績5 成績6

printf("Input the 8 student's number and score:\n");

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

{

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

{

scanf("%d",&num);

student[i][j]=num;

}

}

//輸入壹個您要查找的學號

printf("Input a student's number to compute:");

scanf("%d",&searchn);

//通過for循環查找您想要查詢的學號

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

{

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

{

if(student[i][j]==searchn)//如果輸入的學號存在,求出該學生的平均分並輸出

{

printf("The No.%d student's average is %.2f\n",student[i][0],(student[i][1]+student[i][2]+student[i][3]+student[i][4]+student[i][5]+student[i][6])/6.0);

//找到了想要的學號並計算好該生的平均分後,程序直接退出

return 0;

}

}

}

//輸入的學號不存在,提示沒有找到

printf("not find!\n");

return 0;

}

  • 上一篇:arcgis鑲嵌柵格特別慢
  • 下一篇:12歲可以學編程嗎?
  • copyright 2024編程學習大全網