循环读入字符,遇到\n累计行数,最终输出累计值即可。
以EOF作为终止条件的代码如下:
#include
int main()
{
int cnt = 1;//最少会输出一行,每遇到一个换行,表示多输入了一行。
int c;
while((c = getchar())!=EOF)
{
if(c == '\n') cnt++;//统计行数。
}
printf("%d\n",cnt);
return 0;
}
一楼的那个,中间有出现!通不过吧?比如:hello!
#include
#define MAX 10000
int main()
{
char ch[MAX];
int t=0;
while(get(ch),strcmp(ch,"!")
t++;
printf("行数=%d\n",t);
return 0;
}
//---------------------------------------------------------------------------
#include
int main(void)
{
int st=0;
char c;
while ((c=getchar())!='!')
st+=c=='\n'?1:0;
printf("%d\n",st);
return 0;
}
//---------------------------------------------------------------------------
main()
{int a;
for(a=100;a<200;a++)
{ if(a%3==0) continue;
printf("%d",a);
getch();
}
}