如何控制每行输出的个数
//把100~200之间的不能被3整除的数输出
#include<stdio.h>
int main()
{
int n;
for(n=100;n<=200;n++)
{
if(n%3!=0)
{
printf("%d,",n);
}
}
printf("\n");
}
//输出:
//100,101,103,104,106,107,109,110,112,113,115,116,118,119,121,122,124,125,127,128,
//130,131,133,134,136,137,139,140,142,143,145,146,148,149,151,152,154,155,157,158,
//160,161,163,164,166,167,169,170,172,173,175,176,178,179,181,182,184,185,187,188,
//190,191,193,194,196,197,199,200,
//Press any key to continue
//能不能控制一行4个,代码怎么加?
[解决办法]
错了, 修改为:
#include<stdio.h>
int main()
{
int n;
int count_of_found;
count_of_found = 0
for(n=100;n<=200;n++)
{
if (n%3!=0)
{
printf("%d,",n);
count_of_found++;
if (count_of_found % 4 == 0) {
printf("\r\n");
}
}
}
printf("\n");
}