c语言 4-14 根据输入的整数,循环显示1234567890

 

1、while语句

#include <stdio.h>

int main(void)
{
    int i = 1, j;
    puts("please input an integer.");
    do
    {
        printf("j = "); scanf("%d", &j);
        if (j <= 0)
            puts("the range of j is: > 0 ");
    }
    while (j <= 0);
    
    while (i <= j)
    {
        printf("%d", i % 10);
        i++;
    }
    putchar('\n');
    
    return 0 ;
}

 

2、for语句

#include <stdio.h>

int main(void)
{
    int i, j;
    puts("please input an integer.");
    do
    {
        printf("j = "); scanf("%d", &j);
        if (j <= 0)
            puts("the range of j is: > 0");
    }
    while (j <= 0);
    
    for (i = 1; i <= j; i++)
    {
        printf("%d", i % 10);
    }
    putchar('\n');
    
    return 0;
}

 

3、do语句

#include <stdio.h>

int main(void)
{
    int i = 1, j;
    puts("please input an integer.");
    do
    {
        printf("j = "); scanf("%d", &j);
        if (j <= 0)
            puts("the range of j is: > 0");
    }
    while (j <= 0 );
    
    do
    {
        printf("%d", i % 10);
        i++;
    }
    while (i <= j);
    putchar('\n');
    
    return 0;
}

 

上一篇:Pytorch使用ReduceLROnPlateau来更新学习率


下一篇:PTA QQ帐户的申请与登陆(map的简单应用)