嵌入式学习day6
- 作业1: 输入一个字符串,输出大写,如果大写不存在,则提示大写不存在
- 作业2: 输入一个字符串,计算大写的个数,小写的个数,数字的个数,特殊字符的个数
- 作业3:输入一个字符串,实现升序排序,并输出
- 作业4: 输入一个字符串,实现字符串逆置
作业1: 输入一个字符串,输出大写,如果大写不存在,则提示大写不存在
#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: 输入一个字符串,计算大写的个数,小写的个数,数字的个数,特殊字符的个数
#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:输入一个字符串,实现升序排序,并输出
#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: 输入一个字符串,实现字符串逆置
#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");
}