在这段代码中,{if((scanf("%d",& a [I])== 1))C ++;做什么和'== 1'检查 [英] In this code what is { if((scanf("%d", &a[I])==1)) C++; } doing and what is '==1' checking

查看:146
本文介绍了在这段代码中,{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.


这篇关于在这段代码中,{if((scanf(&quot;%d&quot;,&amp; a [I])== 1))C ++;做什么和'== 1'检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆