输出练习收获

来源:互联网 发布:易语言制作下载器源码 编辑:程序博客网 时间:2024/06/10 03:39

while(scanf("%d%d",&a,&b)!=EOF)


  scanf("%d%d\n",&a,&b);

  scanf("%d%d\n",&a,&b);使用scanf需要换行时不要加\n,不然下一行printf不能输出结果


while((scanf("%d",&n))!=EOF,n)

        while((scanf("%d",&n))!=EOF&&n) 功能相同,n不等于0,且还在继续输入

 

  

For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.
对于每一组输入整数,你应该在一行输出它们的和,你必须注意输出之间有一条空行。

#include<stdio.h>
int  main(){


         int a,s,i,n;
   
        scanf("%d",&n);
    while(n--){
    s=0;
scanf("%d",&a);
while(a--){
 
         scanf("%d",&i);
    
    s+=i;
}
    printf("%d\n",s);
if(n!=0){
printf("\n");
}
   
 }

}              并且最后一行结束不能再有空行 if(n!=0){
printf("\n");
                                          }


For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line. 
对于每对输入整数a和b,你应该输出a和b的和,然后是一条空行。  此描述不用再加if判断了
    
 


原创粉丝点击