再請教一個問題,這是一個陣列的程式。就是有五個server以及各server的user有多少人?如今輸入一個server的號碼,就去列出該server的user是多少人。如果輸入的server不在其中就回答not listed。
引用:
#include <stdio.h>
int main(void)
{
int serverusers[5][2]=
{
1,14,
2,28,
3,19,
4,8,
5,15};
int server;
int i;
printf("enter the server number: \n");
scanf("%d",&server);
//look it up in the table.
for(i=0;i<5;i++)
if(server==serverusers[i][0]){
printf("there are %d users on server %d.\n",serverusers[i][1],server);
break;
}
//report error if not found.
if(i==5) printf("server not listed.\n");
return 0;
}
|
為何最後以i等於5的話來判定輸入的值不在預設之中?
thanks