scanf的返回值是输入数值的个数。

来源:互联网 发布:mac迅雷下载失败提示 编辑:程序博客网 时间:2024/06/08 08:19
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. 
 

输入格式

The input will consist of a series of integers n, one integer per line. 
 

输出

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer. 
 

样例输入

1
100

样例输出

1

5050

void main(){int a,b,c;    c=scanf("%d %d",&a,&b);    printf("%d",c);}为什么我输入a 1  , c的值就为0,输入1 a,c的值为1

scanf返回接收到的变量值的个数。 int  a,b,c。a 1进去时,试图用字符‘a’对a赋值,肯定是错的,于是退出,返回成功接收到赋值的个数 0.1 a进去时,首先a能获取1.但b不能获取'a',于是返回只是1 如果是  1 1的话,那就都成功,返回2

0 0
原创粉丝点击