Need to do as follows
1> every line have lineNum
2> show the number that can't divide into divisor; if the number can't divide into the divisor, then replace it by <SPACE>
continue_test.c
#include<stdio.h>
#define fromNum 1
#define termNum 30
#deine divisor 2
#define lineNum 5
int main(int argc, char *agrv[])
{
int number, flag;
for(number = fromNum, flag = 0; number <= termNum; flag++, number++)
{
if(!(flag%lineNum) && flag)
{
printf("\n");
}
if(!(number%divisor))
{
printf(" ");
continue;
}
else
printf(" %02d ", number);
}
printf("\n");
}
Makefile
make:
gcc -o swit_test swit_test.c
clean:
rm -rf swit_test
The Result as follows
[root@localhost switch_test]# ./swit_test
01 03 05
07 09
11 13 15
17 19
21 23 25
27 29
PS. this program can be extension from the define
本文介绍了一个使用C语言编写的程序,该程序能够按照特定规则筛选并输出一系列数字。通过定义起始数、终止数、除数及每行输出的数字数量等参数,程序能够有效地过滤掉能被指定除数整除的数字,并将剩余数字按行输出。

6354

被折叠的 条评论
为什么被折叠?



