A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© xu不是许 中级黑马   /  2015-10-29 22:27  /  665 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


译密码
译码有约定:即将输入的字母译成该字母之后的第四个字母,其它字符不变,如A译成E,a译成z,China!择成Glmre!,参考程序如下:
#include <stdio.h>
int main()
{
    char c;
    while ((c = getchar()) != '\n')//键盘输入的字符,如不是回车,则循环继,如果是,则执行执行{}
    {
        if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')//判断大小写
        {
            c=c+4;
            if (c > 'Z' && c <= 'Z' +4 || c > 'z') c = c - 32;//如果加密后的字符比‘z'或者'Z'大,则减去32,注意同个字母的大写字母比小写字母要小32。如“A”<“a”
        }
        printf("%c",c);
    }
    printf("\n");
    return 0;
}
输出九九乘法表
#include<stdio.h>
int main()
{
    int i, j, p = 1;
    for (j = 1; j < 9; j++)
    {
        printf("\n");
        for (i = 1; i <= j; i++)
        {
            p = j * i;
            printf("\t%d*%d=%d", i, j, p);
        }
    }
    printf("\n");
    return 0;
}
输入一行字符,分别统计出其中的英文字母、空格、数字和其它字符的个数。
#include <stdio.h>
int main()
{
    char c;
    int letter = 0, space = 0, number = 0, other = 0;
    printf("input a row of letter:\n");
    while ((c = getchar()) != '\n')
    {
        if  (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
            letter++;
        else if (c == ' ')
            space++;
        else if(c >= '0' && c <= '9')
            number++;
        else
            other++;
    }
    printf("letter=%d,space=%d,number=%d,other=%d\n", letter, space, number, other);
}
有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其中英文大写字母、文小写字母、数字、空格和其它字符的个数
#include <stdio.h>

int main()
{
    int i,j;
    int upp,low,gid,spa,oth;
    char text[3][80];
    upp=0;low=0;gid=0;spa=0;oth=0;
    for (i=0;i<3;i++)
    {
        gets(text);   /*text表示第i行*/
        for (j=0;j<80 && text[j]!='\0';j++)
        {
            if (text[j]>='A' && text[j]<='Z')
                upp++;//大写字母+1
            else  if (text[j]>='a' && text[j]<='z')
                low++;//小写字母+1
            else  if (text[j]>='0' && text[j]<='9')
                gid++;//数字+1
            else  if (text[j]==' ')
                spa++;//空格+1
            else oth++;//其他字符+1
        }
    }
    printf("upp=%d,low=%d,gid=%d,spa=%d,oth=%d\n",upp,low,gid,spa,oth);
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马