c语言问题1、 编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出

作者&投稿:姚府 (若有异议请与网页底部的电邮联系)
1、 编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出~

//C语言的,VC2005通过
#include
#include
int main(int argc, char *argv[])
{
char str [20];//最多19个字符
int n,half,i;
char tmp;
memset(str, 0, 20);
scanf("%s", str);
printf("Before: %s
", str);
n=strlen(str)-1;
half=n/2;
for(i=0;i<=half;i++)
{
tmp=str[i];
str[i]=str[n-i];
str[n-i]=tmp;
}

printf("After : %s
", str);
fflush(stdin);
getch();
return 0;
}

1、
#include "stdafx.h"

int main(int argc, char* argv[])
{
int n;
printf("要输入的字符串长度为:
");
scanf("%d",&n);
printf("输入字符串:
");
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("逆序字符串为:
");
puts(ch);
return 0;
}


2、
#include "stdafx.h"
int main(int argc, char* argv[])
{
int n;
printf("要输入的字符串长度为:
");
scanf("%d",&n);
printf("输入字符串:
");
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("输出字符串:
");
puts(ch);
return 0;
}

3、
#include "stdafx.h"
#include

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;
}

已通过调试,结果正确。
#include <stdio.h>
void main(void)
{
unsigned char i = 0, j, temp1[200], temp2[200];
printf("\n\n\n Please Input yuan_wenzi: ");
scanf("%s", temp1); /*输入字符串到TEMP1*/
while(temp1[i] != '\0') {temp2[i] = temp1[i]; i++;} /*暂时存到TEMP2*/
for (j = 0; j < i; j++) temp1[j] = temp2[i - 1 - j]; /*反序后还在TEMP1*/
temp2[j] = temp1[i];
printf("\n\n yuan_wenzi: %s\n", temp2);
printf(" \n fan__wenzi: %s\n\n", temp1); /*输出反序后的TEMP1*/
}

//先写的,已通过调试,结果正确,程序及注释如下:
#include<stdio.h>
void main()
{
char s[20],*p;
int i;
scanf("%s",s);//输入一个长度小于20的字符串,由s[20]限定,要改字符串长度就改字符串数组大小
p=s;//将字符串首地址赋给指针p
while(*p!='\0') p++;//让指针一直指到字符串结束符
while(p!=s) //倒序输出字符串中字母,直到字符串首地址
{
p--;
printf("%c",*p);
}
}
有问题可以HI我··

//C语言的,VC2005通过
#include <stdio.h>
#include <memory.h>
int main(int argc, char *argv[])
{
char str [20];//最多19个字符
int n,half,i;
char tmp;
memset(str, 0, 20);
scanf("%s", str);
printf("Before: %s\n", str);
n=strlen(str)-1;
half=n/2;
for(i=0;i<=half;i++)
{
tmp=str[i];
str[i]=str[n-i];
str[n-i]=tmp;
}

printf("After : %s\n", str);
fflush(stdin);
getch();
return 0;
}



#include<stdio.h>
main()
{
char str[80],c;
int i,j=0,p;
gets(str);
for(i=0;str[i]!='\0';i++)
j++;
for(i=-;i<p/2;i++)
{c=a[i];a[i]=a[j-1];
j=j-1;}
printf("%d",a[i]);
}

#include<stdio.h>
void main() { char str[256],*p,*q,c;
  gets(str); p=q=str; while ( *q ) q++; q--;
  while  ( p<q ) { c=*p; *p=*q; *q=c; p++; q--; }
  printf("%s
",str);
}


#include "stdio.h"
#define N 100000
int main()
{
char a[N];
int i=0;
while(scanf("%s",a)!=EOF){
printf("%s\n",a);
while(a[i]!='\0')
i++;
for(;i>0;i--)
printf("%c",a[i-1]);
printf("\n");
}
return 0;
}
你可以尝试一下这个,你要求的strlen没有使用,你可以运行一下


蒲县17631917864: c语言怎么从键盘输入数据,用程序怎么编 -
祗心宜妥: 我用的是vc6,一般格式是: #include<iostream> using namespace std; int main() {cin>>a;return 0; }在cin>>的后面可以输入数据

蒲县17631917864: C语言 编写程序,从键盘输入一个正数,计算该数的平方根. -
祗心宜妥: # include <stdio.h> #include<math.h> int main() {double x;scanf("%lf",&x);printf("%lf\n",sqrt(x));return 0; }

蒲县17631917864: 编写c语言程序,对于从键盘上输入的一行字符,该程序能将其依次显示在屏幕上. -
祗心宜妥: 1 2 3 4 5 6 7 8#include <stdio.h> #include <string.h> intmain(){chars[100];gets(s);printf("%s",s);return0; }

蒲县17631917864: 用C语言编写一个程序:从键盘输入若干个字符,分别统计其中字母符号?
祗心宜妥: #include void main() { int i=0,n=0,m=0,j=0,k=0; char str[100]; printf("please input one string.\n"); scanf("%s",str); printf("\n"); while(str[i]!='\0') { if(str[i]>='a'&&str[i]='A'&&str[i]='0'&&str[i] 全部

蒲县17631917864: 一个编写C程序的问题(1)谢谢编写一个C程序,从键盘输入一个长度
祗心宜妥: main() { int a[10],i,min; for(i=0;ia[i]) min=i; printf("%d\n",i); } }

蒲县17631917864: 用c语言编写一个程序,从键盘上输入两个字符给字符变量a,b,并输出变量a,b的值.第二题编写一个程序,从键盘上输入一个整数,一个浮点数,一个字符分... -
祗心宜妥:[答案] #include int main(){char a,b;a=getchar();scanf("%c", &b );printf("a=%c\n", a );printf("b=%c\n", b );return 0;}#include int main(){int i;double d ;char c;printf("input char :" );c=getchar();putchar(c);...

蒲县17631917864: C语言编程问题:(1)编写程序,从键盘输入2个单精度实数,求他们的差? -
祗心宜妥: 给你写第一个吧,手机不好打.电脑的话两下! main() { float a,b; scanf("%f%f",&a,&b); printf("%f",a-b); } 最基本的实现,楼主还需要另两个可以追一下,明天上网发给你

蒲县17631917864: 1、 编制程序:对键盘输入的字符串进行逆序,逆序后的字符串仍然保留在原来字符数组中,最后输出 -
祗心宜妥: //C语言的,VC2005通过 #include #include int main(int argc, char *argv[]) { char str [20];//最多19个字符 int n,half,i; char tmp; memset(str, 0, 20); scanf("%s", str); printf("Before: %s\n", str); n=strlen(str)-1; half=n/2; for(i=0;i<=half;i++) { tmp=str[i]...

蒲县17631917864: c语言编程题编写一个c程序,要求从键盘输入两个数,并依据提示输入的数字,选择对这两个数的运算, -
祗心宜妥: #include "stdio.h"// void main(void){int a,b,c;printf("请输入两个十进制整数!\na=");scanf("%d",&a);printf("b=");scanf("%d",&b);printf("请输入运算符(1加法;2乘法;3除法):\n运算符:"); for(;;){scanf("%d",&c);...

蒲县17631917864: 编写一个c语言程序 从键盘输入x,y,z这三个整型变量 并输出其中的最小值 -
祗心宜妥: #include<stdio.h> int main() {int x,y,z,min; scanf("%d%d%d",&x,&y,&z); min=x; if(min<y)min=y; if(min<z)min=z; printf("%d\n",min); return 0; }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网