如题所述
看用什么方法输入数据,每成功输入1个数据,你用累加器加1。
常用输入数据函数是 scanf(), 这个函数能返回成功读入的数据个数。
例如: n = scanf("%d %f %lf %s", &k, &a, &x, s);
成功读入4个,n得4,成功读入3个,n得3,。。。成功读入1个,n得1,
一个也没成功,n得 0。
如果循环读入:
int sum=0, i=0;
while(...){
n = scanf("%d %f %lf %s", &k[i], &a[i], &x[i], s[i]);
sum = sum + n;
i++;
}
printf("成功读入的数据个数是%d\n",sum);
常用输入数据函数是 scanf(), 这个函数能返回成功读入的数据个数。
例如: n = scanf("%d %f %lf %s", &k, &a, &x, s);
成功读入4个,n得4,成功读入3个,n得3,。。。成功读入1个,n得1,
一个也没成功,n得 0。
如果循环读入:
int sum=0, i=0;
while(...){
n = scanf("%d %f %lf %s", &k[i], &a[i], &x[i], s[i]);
sum = sum + n;
i++;
}
printf("成功读入的数据个数是%d\n",sum);
温馨提示:答案为网友推荐,仅供参考