zoukankan      html  css  js  c++  java
  • 打印沙漏1

    1 #include<stdio.h>

    int main()
    {
    int sum;
    char c;
    int n;
    scanf("%d %c", &sum, &c);
    for (int i = 0; i <= 100; i++)
    {
    if ((ii) * 2 - 1 == sum)
    {
    n = i;
    break;
    }
    else if ((i
    i) * 2 - 1 > sum)
    {
    n = i - 1;
    break;
    }
    }
    int t = n;
    int counter = 0;
    while (t)
    {
    for (int i = 1; i <= counter; i++)
    {
    printf(" ");
    }
    for (int i = 1; i <= (2 * t - 1); i++)
    {
    printf("%c", c);
    }

    printf(" ");
    counter++;
    t--;
    }
    t = 2;
    counter = n - 2;
    while (t<=n)
    {
    for (int i = 1; i <= counter; i++)
    {
    printf(" ");
    }
    for (int i = 1; i <= (2 * t - 1); i++)
    {
    printf("%c", c);
    }

    printf(" ");
    counter--;
    t++;
    }
    if (sum == 0)
    printf("0 ");
    else
    printf("%d ", sum - (2 * n*n - 1));
    system("pause");
    return 0;
    }

    2 运用while语句打印出上半部分的行数,再用两个for语句确定上下两部分的行数,for语句中再镶嵌for语句确定“*”与空格的个数

    3 while与for的顺序颠倒部分,然后请教教了同学

  • 相关阅读:
    认证-权限-频率组件
    视图组件
    序列化类
    解析模块
    异常模块
    响应模块分析
    请求模块分析
    cbv请求分析
    django中的restful规范
    web接口与restful规范
  • 原文地址:https://www.cnblogs.com/xzhxzh/p/10403516.html
Copyright © 2011-2022 走看看