判断读取数据结束用scanf()!=EOF
#include <stdio.h> #include <string.h> int main() { int a,b; int sign=0,w=0; while(scanf("%d %d",&a,&b)!=EOF) { if(b==0&&sign==0) { if(w==0) printf("0 0"); else printf(" 0 0"); } else if(b!=0) { sign=1; a=a*b; b=b-1; if(w==0) { printf("%d %d",a,b); w=1; } else printf(" %d %d",a,b); } } printf(" "); return 0; }