程式碼是這樣的
#include
/*用for迴圈實現*/
void main()
{
int n;
int m;
printf("please input n\n");
scanf("%d",&n);
for(int i = 1; i <= n; i++)
if(i % 3 == 0 || i % 7 == 0)
m++;
printf("%-3d",i);
if(m % 10 == 0)
printf("\n");
}
/* 用while迴圈實現*/
int i = 1;
while(i <= n)
i++;
程式碼是這樣的
#include
/*用for迴圈實現*/
void main()
{
int n;
int m;
printf("please input n\n");
scanf("%d",&n);
for(int i = 1; i <= n; i++)
if(i % 3 == 0 || i % 7 == 0)
{
m++;
printf("%-3d",i);
if(m % 10 == 0)
printf("\n");
}
printf("\n");
}
/* 用while迴圈實現*/
#include
void main()
{
int n;
int m;
int i = 1;
printf("please input n\n");
scanf("%d",&n);
while(i <= n)
{
if(i % 3 == 0 || i % 7 == 0)
{
m++;
printf("%-3d",i);
if(m % 10 == 0)
printf("\n");
}
i++;
}
printf("\n");
}