如题所述
#include<stdio.h>
/*用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<stdio.h>
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");
}
/*用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<stdio.h>
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");
}
温馨提示:答案为网友推荐,仅供参考