3个C语言小题目~~~

来源:百度知道 编辑:UC知道 时间:2024/05/29 20:29:26
1、编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出。
2、编写程序:对从键盘输入的任意字符串,将其中所有的大写字母改为小写字母,而所有小写字母改为大写字母,其它字符不变
3、编写程序:从键盘输入4个字符串(长度<20),存入二维字符数组中。然后对它们进行排序,最后输出
本人刚刚学习C语言,所以代码不要太难了,呵呵。。。。第一题第二题算法基本会,就是不知道字符串数组该如何定义。。因为不知道从键盘上输入的字符是多少啊,第三题是不会了~~~~谢谢大家赐教,O(∩_∩)O~
第三题不用从键盘输入,直接用
Spanish
China
America
Japan
4个字符串

1、
#include "stdafx.h"

int main(int argc, char* argv[])
{
int n;
printf("要输入的字符串长度为:\n");
scanf("%d",&n);
printf("输入字符串:\n");
char* ch = new char[n];
scanf("%s",ch);

for(int i=0;i<n/2;i++)
{
char temp = ch[i];
ch[i] = ch[n-1-i];
ch[n-1-i]=temp;
}
printf("逆序字符串为:\n");
puts(ch);
return 0;
}

2、
#include "stdafx.h"
int main(int argc, char* argv[])
{
int n;
printf("要输入的字符串长度为:\n");
scanf("%d",&n);
printf("输入字符串:\n");
char* ch = new char[n];
scanf("%s",ch);

for(int i=0;i<n;i++)
{
if(ch[i]<='Z')
ch[i] += 32;
else
if(ch[i]>='a')
ch[i] -= 32;
}
printf("输出字符串:\n");
puts(