本文介绍了scanf函数中的什么/ n在我的程序中执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我从scanf函数中删除\ n然后我的代码运行良好,它不会要求第二个输入,它没有任何作用,并且当我输入0然后它不跳转到下一行既不停止程序但是之后再次给0输入它会停止程序,所以PLZ解释了什么在这里扮演角色以及它在程序中创造了什么区别
我尝试过:
if i remove \n from scanf function then my code runs well and it doesnot ask for second input which has no role in it and and also when i enter 0 then it doesnot jumpto next line neither it stops the program but after giving 0 input again it stops the program so plz explain what \n is playing role here and what difference it created in program
What I have tried:
#include<stdio.h>
#include<stdlib.h>
int main()
{
float testno=0,scoreentered,sum=0,avg;
printf("enter 0 to stopthe program\n");
do
{
printf("testno:%f avg:%f\n",testno,avg);
printf("enter score");
scanf("%f\n",&scoreentered);
sum+=scoreentered;
testno++;
avg=sum/testno;
}
while(scoreentered!=0);
}
输出
output
enter 0 to stopthe program
testno:0.000000 avg:0.000000
enter score1
3
testno:1.000000 avg:1.000000
enter score0
testno:2.000000 avg:2.000000
enter score0
~/workspace/ $
推荐答案
这篇关于scanf函数中的什么/ n在我的程序中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!