scanf参数输入问题

来源:互联网 发布:医用心理测评软件 编辑:程序博客网 时间:2024/06/07 09:40

 

1、scanf("%d%d%d",&a,&b,&c)   /*此处输入的时候需要根据""内的格式进行*/

如果在同一行输入的话,3个数直接要用 空格 隔开。---原理不明,需要研究scanf机理。

如果是单独分3行输入的话,则每输入一个就回车一下。---回车好像是 flush 的作用。

 

2、scanf("%d,%d,%d",&a,&b,&c))  /*此处输入的时候需要根据""内的格式进行*/

此时只能在同一行中输入,且3个数之间要用逗号隔开。

 

附一个小程序:

 

 #include<stdio.h>

int main()
{
 int a,b,c;
 
 printf("please input the length of the triangle three lines:");
 
 if(3 != scanf("%d,%d%d",&a,&b,&c))  /*此处输入的时候需要根据""内的格式进行*/
 {
    printf("the input is error/n"); 
 }
 
 if((a+b>c)&&(a+c>b)&&(b+c>a))
 {
    if((a == b)&&(a == c))
    {
       printf("等边三角形/n"); 
    } 
    else if((a == b)||(a == c)||(b == c))
    {
       printf("等腰三角形/n");
    }
    else
    {
       printf("不等边三角形/n");
    }
 }
 else
 {
   printf("the inputs can't be a triangle/n");
 } 
 
  return 0; 
}