第五章

作者: Zdhj | 来源:发表于2017-10-10 22:33 被阅读4次

    include<stdio.h>

    int main()
    {
    char c;
    int l = 0, s = 0, d = 0, o = 0;
    printf("请输入一行字符:\n");
    while ((c = getchar()) != '\n')
    {
    if (c >= 'a'&&c <= 'z' || c >= 'A'&&c <= 'Z')
    l++;
    else if (c == ' ')
    s++;
    else if (c >= '0'&&c <= '9')
    d++;
    else
    o++;
    }
    printf("字母数:%d,空格数:%d,数字数:%d,其余数:%d", l, s, d, o);
    return 0;
    }

    include<stdio.h>

    int main()
    {
    int n,s1,s2,i,j,k;
    s1 = 0; s2 = 0; k = 1;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
    for (j = 1; j <= i; j++)
    {

            s1 = k * 2 + s1;
            k = 10 * k;
        }
        s2 = s1 + s2;
    }
    printf("result is %d\n", s2);
    return 0;
    

    }

    include<stdio.h>

    int main()
    {
    float j,k,i,s1,s2,s3;
    s1 = 0; s2 = 0; s3 = 0;
    for (k = 1; k <= 100; k++)
    {
    s1 = s1 + k;
    }
    for (i = 1; i <= 50; i++)
    {
    s2 = s2 + i*i;
    }
    for (j = 1; j <= 10; j++)
    {
    s3 = s3 + 1 / j;
    }
    printf("total number is %f.\n", s1 + s2 + s3);
    return 0;
    }

    include<stdio.h>

    int main()
    {
    int t,t1,t2,t3;
    for (t = 100; t <= 999; t++)
    {

        t1 = t / 100;
        t2 = t / 10 % 10;
        t3 = t % 10;
        if (t1*t1*t1 + t2*t2*t2 + t3*t3*t3 != t) continue;
        printf("水仙数有:%d.\n", t);
    }
    return 0;
    

    }

    include<stdio.h>

    int main()
    {
    double i,j, k,a,b,sum;
    j = 1; k = 2; sum = 2;
    for (i = 1; i <= 19; i++)
    {
    a = j + k;
    b = a / k;
    j = k;
    k = a;

        sum = sum + b;
    }
    printf("sum: %.2f\n", sum);
    return 0;
    

    }

    include<stdio.h>

    int main()
    {
    float i,s,h;
    s = 100; h = s/2;
    for (i = 2; i <= 10; i++)
    {
    s = s+2*h;
    h = h / 2;
    }
    printf("total distance is %f.\n", s);
    printf("10th hight is %f.\n", h);
    return 0;
    }

    include<stdio.h>

    int main()
    {
    int i, j;
    printf("甲队A、B、C队员编号为1、2、3;乙队同理为1、2、3\n");
    for (i = 1; i <= 3; i++)
    {
    for (j = 1; j <= 3; j++)
    {
    if ((i == 1 && j == 1)||(i==3&&j==1)||(i==3&&j==3)) continue;
    printf("甲队%d号对阵乙队%d号\n", i, j);

        }
    }
    return 0;
    

    }
    关于17题的标准答案:

    include<stdio.h>

    int main()
    {
    char i, j, k;
    for (i = 'x'; i <= 'z'; i++)
    for (j = 'x'; j <= 'z'; j++)
    if (i != j)
    for (k = 'x'; k <= 'z'; k++)
    if (i != k&&j != k)
    if (i != 'x'&&k != 'x'&&k != 'z')
    printf("A--%c\nB--%c\nC--%c\n", i, j, k);
    return 0;
    }

    相关文章

      网友评论

          本文标题:第五章

          本文链接:https://www.haomeiwen.com/subject/jwzbyxtx.html