C语言 几个重要的ascii值

新知

  • ascii 码记忆,利用字符达到ascii码效果
    0 - 9 ascii 是 48-57
    ‘A’ - ‘Z’ ascii 是 65-90
    ‘a’ - ‘Z’ ascii 是 97-122
  • switch case 的常量表达式的可取类型
    switch的case 常量表达式的 值 必须要是整数,因为只有整数才可以列举 ,故可以是 整型、char 型、枚举类型
    case 9:
    case ‘A’:
  • ‘\n’占用一个字节。

练习根据ascii码

	练习:
		从键盘输入一个字符
			如果是小写字母则把它转成对应的大写字母
			如果是大写字母则把它转成对应的小写字母
			如果是数字,就不改变
				然后输出
			其它的不处理,也不输出

int main()
{
    char test ;

    scanf("%c", &test);

    if (test >= 65 && test <= 90)//'A' - 'Z'
        printf("%c\n", test + 32);//输出 'a' - 'z'
    else if (test >= 97 && test <= 122)// 'a' - 'z'
        printf("%c\n", test - 32);//输出 'A' - 'Z'
    else if (test >= 48 && test <= 57)// 0 - 9
        printf("%c\n", test);//输出0 - 9
    else//其他
        ;
}

//一般写大于’0’,小于’9’就不用记ascii码了
int main()
{
    char test ;

    scanf("%c", &test);

    if (test >= 'A' && test <= 'Z')//'A' - 'Z'
        printf("%c\n", test + 32);//输出 'a' - 'z'
    else if (test >= 'a' && test <= 'z')// 'a' - 'z'
        printf("%c\n", test - 32);//输出 'A' - 'Z'
    else if (test >= '0' && test <= '9')// 0 - 9
        printf("%c\n", test);//输出0 - 9
    else//其他
        printf("unknow\n");
}

请你写一个程序判断7是否是质数
int main()
{
    int i;
    int a;
    scanf("%d", &a);

    for (i = 2; i < a; i++)
    {
        if (a % i == 0)
        {
            printf("不是质数\n");
            break;
        }
    }
    if(i == a)
        printf("是质数\n");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值