在这段代码中,{if((scanf("%d",& a [I])== 1))C ++;做什么和'== 1'检查
{
int a [50];
int i,j,c = 0;
printf(输入输入\ n) ;
for(i = 0; i< 50; i ++)
{
if((scanf(%d) ,& a [i])== 1))
c ++;
}
printf(No。输入是%d,c);
返回0;
}
我是什么试过:
c程序找不到。插入后数组中的输入,插入时不计数。
{
int a[50];
int i,j,c=0;
printf("enter the inputs\n");
for(i=0;i<50;i++)
{
if((scanf("%d",&a[i])==1))
c++;
}
printf("No. of inputs are %d",c);
return 0;
}
What I have tried:
c program to find the no. of inputs in an array after inserting and without counting while inserting.
分解:
Break it down:
if((scanf("%d",&a[i])==1))
c++;
从内心开始:
Start with the inner most:
&a[i]
数组中第i个元素的地址。每次代码绕循环,这都会改变。
Address of the "i"th element on the array. Each time the code goes round the loop, this changes.
scanf("%d",&a[i])
这是一个标准库函数: scanf - C ++ Reference [ ^ ]它根据格式从标准输入读取。在这种情况下,格式为%d,表示读取十进制整数第二个参数是您要存储值的地址。
This is a standard library function: scanf - C++ Reference[^] it reads from the standard input, according to the format. in this case, the format is %d which means "read a decimal integer" The second parameter is the address of the place you want to store the value.
if((scanf("%d",&a[i])==1))
...
如果scanf函数成功读取一个整数,则执行下一个语句或语句块。
If the scanf function successfully read one integer, then execute the next statement or statement block.
c++
增加 c
一个。
所以...它从用户读取整数,将它们存储在数组中,并对它们进行计数。
Increment c
by one.
So...it reads integers from the user, stores them in and array, and counts them.