标签:div oid input char while print putchar c语言 put
输出小于输入值的所有正偶数。
1、while语句
#include <stdio.h>
int main(void)
{
int i = 2, j;
puts("please input an integer.");
printf("j = "); scanf("%d", &j);
while ( i <= j)
{
printf("%d ", i);
i += 2;
}
putchar(‘\n‘);
return 0;
}
2、while语句
#include <stdio.h>
int main(void)
{
int i = 1, j;
puts("please input an integer.");
printf("j = "); scanf("%d", &j);
while (i <= j)
{
if (i % 2 == 0)
printf("%d ", i);
i++;
}
putchar(‘\n‘);
return 0;
}
3、while语句
#include <stdio.h>
int main(void)
{
int i;
puts("please input an integer.");
printf("i = "); scanf("%d", &i);
while (i > 0)
{
if (i % 2 == 0)
printf("%d ", i);
i--;
}
putchar(‘\n‘);
return 0;
}
4、for语句
#include <stdio.h>
int main(void)
{
int i, j;
puts("please input an integer.");
printf("j = "); scanf("%d", &j);
for (i = 2; i <= j; i+=2)
{
printf("%d ", i);
}
putchar(‘\n‘);
return 0;
}
5、for语句
#include <stdio.h>
int main(void)
{
int i, j;
puts("please input an integer.");
printf("j = "); scanf("%d", &j);
for (i = 1; i <= j; i++)
{
if (i % 2 == 0)
printf("%d ", i);
}
putchar(‘\n‘);
return 0;
}
6、for语句
#include <stdio.h>
int main(void)
{
int i;
puts("please input an integer.");
printf("i = "); scanf("%d", &i);
for (i; i > 0; i--)
{
if (i % 2 == 0)
printf("%d ", i);
}
putchar(‘\n‘);
return 0;
}
7、do语句
标签:div oid input char while print putchar c语言 put
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14675088.html