3个C语言小题目~~~

1、编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出。2、编写程序:对从键盘输入的任意字符串,将其中所有的大写字母改为小写字母,而所... 1、编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出。
2、编写程序:对从键盘输入的任意字符串,将其中所有的大写字母改为小写字母,而所有小写字母改为大写字母,其它字符不变
3、编写程序:从键盘输入4个字符串(长度<20),存入二维字符数组中。然后对它们进行排序,最后输出
本人刚刚学习C语言,所以代码不要太难了,呵呵。。。。第一题第二题算法基本会,就是不知道字符串数组该如何定义。。因为不知道从键盘上输入的字符是多少啊,第三题是不会了~~~~谢谢大家赐教,O(∩_∩)O~
第三题不用从键盘输入,直接用
Spanish
China
America
Japan
4个字符串
展开
 我来答
平凡而执著
2009-04-02 · TA获得超过368个赞
知道答主
回答量:76
采纳率:0%
帮助的人:0
展开全部
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(ch);
return 0;
}

3、
#include "stdafx.h"
#include <string.h>

int main(int argc, char* argv[])
{
char ch[4][20]={"Spanish","China","America","Japan"};
char temp[20];
for(int i=0;i<4;i++)
for(int j=3;j>i;j--)
if(strcmp(ch[j-1],ch[j])>0)
{
strcpy(temp,ch[j-1]);
strcpy(ch[j-1],ch[j]);
strcpy(ch[j],temp);
}
puts("排序之后为:");
for(i=0;i<4;i++)
puts(ch[i]);
return 0;
}
miniappjKnWZgodY2iEG
2009-04-02 · 超过43用户采纳过TA的回答
知道小有建树答主
回答量:160
采纳率:0%
帮助的人:127万
展开全部
/////////////////////////////////////
#include<stdio.h>

int main()
{
char input[50];
int i,j;
char tmp;

puts("please input a string:");
gets(input);

i=0;
j=strlen(input)-1;

while(i<j)
{
tmp=input[i];
input[i]=input[j];
input[j]=tmp;
i++;
j--;
}

puts("after:");
puts(input);

getchar();
return 0;
}

//////////////////////////////////////
#include<stdio.h>
#include<ctype.h>

int main()
{
char input[50];
int i,j;

puts("please input a string:");
gets(input);

i=0;
j=strlen(input);

while(i<j)
{
if(isupper(input[i])) input[i]=tolower(input[i]);
else if(islower(input[i])) input[i]=toupper(input[i]);
i++;
}

puts("after:");
puts(input);

getchar();
return 0;
}

///////////////////////////////////////
#include<stdio.h>
#include<string.h>

int main()
{
char input[4][20]={"Spanish","China","America","Japan"};
int i,j;
char tmp[20];

puts("befor:");
for(i=0;i<4;i++) puts(input[i]);

for(i=0;i<4;i++)
for(j=3;j>i;j--)
if(strcmp(input[j-1],input[j])>0)
{
strcpy(tmp,input[j-1]);
strcpy(input[j-1],input[j]);
strcpy(input[j],tmp);
}

puts("after:");
for(i=0;i<4;i++) puts(input[i]);

getchar();
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
化身智慧
2009-04-07 · TA获得超过237个赞
知道小有建树答主
回答量:130
采纳率:0%
帮助的人:97.3万
展开全部
1、编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出:
*#include<stdio.h>
main()
{
char a[100];
char b[100];
int i=0,n=0,j;
printf("please input a srting:\n");
scanf("%s",a);
while(a[i]!='\0')
{
b[n]=a[i];
n++;
i++;

}
for(i=n,j=n-1;i<2*n;i++)
a[i]=b[j--];
a[i]='\0';//给a赋结束标志
printf("the changed string is:\n");
puts(a);
}
2、编写程序:对从键盘输入的任意字符串,将其中所有的大写字母改为小写字母,而所有小写字母改为大写字母,其它字符不变 :
#include<stdio.h>
main()
{
int i=0;
char a[100];
printf("please input a string:\n");
gets(a);
while(a[i])
{

if(a[i]>='a'&&a[i]<='z')//判断它是否为小写,并转换
a[i]-=32;
else if(a[i]>='A'&&a[i]<='Z')//)//判断它是否为大写,并转换(这里的else很重要啊,不可少)

a[i]+=32;
i++;
}
puts(a);
}
3、编写程序:从键盘输入4个字符串(长度<20),
存入二维字符数组中。然后对它们进行排序,最后输出
#include<stdio.h>
#include<string.h>
main()
{
char a[4][20],c[20];
int i,j;
for(i=0;i<4;i++)
{
printf("please input the %d string:\n",i+1);
gets(a[i]);
}
for(i=0;i<4;i++)
puts(a[i]);
for(i=0;i<4;i++)
for(j=i+1;j<4;j++)
if(strlen(a[i])<strlen(a[j]))//按降序排列
{
strcpy(c,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],c);
}
for(i=0;i<4;i++)
puts(a[i]);
}
这些程序写好后都在vc上编译并做了修改,保证完全可以运行。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友a697f6a
2009-04-02 · 超过11用户采纳过TA的回答
知道答主
回答量:60
采纳率:0%
帮助的人:38.6万
展开全部
你们知道现在的NCRE吗
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式