嵌入式学习day6-作业

作业1: 输入一个字符串,输出大写,如果大写不存在,则提示大写不存在

// C语言专用模板
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
    程序要求:// 输入一个字符串,输出大写,如果大写不存在,则提示大写不存在
*/

int main()
{
    printf("请输入字符串:");
    char str[100] = {0};
    scanf("%s", str);
    int i = 0, a = 0;
    while (str[i] != '\0')
    {
        if (str[i] >= 'A' && str[i] <= 'Z')
            a++;
        else if (str[i] >= 'a' && str[i] <= 'z')
            str[i] = str[i] - 32;
        i++;
    }
    if (a == 0)
    {
        printf("大写不存在\n");
    }
    printf("转换后的字符串为:%s\n", str);

    system("pause");
}

作业2: 输入一个字符串,计算大写的个数,小写的个数,数字的个数,特殊字符的个数

// C语言专用模板
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
    程序要求://  输入一个字符串,计算大写的个数,小写的个数,数字的个数,特殊字符的个数
*/

int main()
{
    printf("请输入字符串:");
    char str[100] = {0};
    scanf("%s", str);
    int len = strlen(str) - 1;
    int a = 0, b = 0, c = 0, d = 0;
    for (int i = 0; i < len; i++)
    {
        if (str[i] >= 'a' && str[i] <= 'z')
        {
            a++;
        }
        else if (str[i] >= 'A' && str[i] <= 'Z')
        {
            b++;
        }
        else if (str[i] >= '0' && str[i] <= '9')
        {
            c++;
        }
        else
        {
            d++;
        }
    }
    printf("大写的个数为:%d", a);
    printf("小写的个数为: %d", b);
    printf("数字的个数为: %d", c);
    printf("特殊字符的个数为: %d", d);
    system("pause");
}

作业3:输入一个字符串,实现升序排序,并输出

// C语言专用模板
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
    程序要求://  输入一个字符串,实现升序排序,并输出
*/

int main()//冒泡排序
{
    printf("请输入字符串:");
    char str[100] = {0};
    scanf("%s", str);
    int len = strlen(str) - 1;
    for (int i = 0; i < len - 1; i++)
    {
        for (int j = 0; j < len - i - 1; j++)
        {
            if (str[j] > str[j + 1])
            {
                char temp;
                temp = str[j];
                str[j] = str[j + 1];
                str[j + 1] = temp;
            }
        }
    }
    printf("升序后的字符串为: %s", str);
    system("pause");
}

作业4: 输入一个字符串,实现字符串逆置

// C语言专用模板
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
    程序要求: 输入一个字符串,实现字符串逆置
    */

int main()
{
    printf("请输入字符串:");
    char str[100] = {0};
    scanf("%s", str);
    int len = strlen(str) - 1;
    int i = 0;
    while (i < len)
    {
        char temp = str[i];
        str[i] = str[len];
        str[len] = temp;
        i++;
        len--;
    }

    printf("逆置的字符串为: %s", str);
    system("pause");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值