Skip to content

Commit 40f642f

Browse files
authored
Create 第一次接触数组初始化
1 parent 85dccbe commit 40f642f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

第一次接触数组初始化

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
int main()
3+
{
4+
int cnt=0,x;
5+
int num[10];
6+
int n;
7+
for (n=0;n<10;n++){
8+
num[n] = 0;
9+
} //6-9行是数组初始化,即把新创建的数组每一个索引所对应的值定义为0.
10+
scanf("%d",&x);
11+
while (x != -1){
12+
num[x] += 1;
13+
scanf("%d",&x);
14+
}
15+
while (x == -1 && cnt < 10) {
16+
printf("%d:%d\n",cnt,num[cnt]);
17+
cnt += 1;
18+
}
19+
return 0;
20+
}

0 commit comments

Comments
 (0)