一个很简单的C语言的问题 逆序输出

micro1984 2004-11-10 07:22:14
定义一个指针数组
输入不定的整数,以\n结束
要求逆序输出
我做了一遍老有错
哪位大哥帮一下忙吧
把定义的部分还有关键的地方写一下就可以啦
先谢啦
...全文
718 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
skkme 2004-11-10
  • 打赏
  • 举报
回复
有点弄不懂数组的用法。
nice90 2004-11-10
  • 打赏
  • 举报
回复
对不起,是可以的,我抄错了。但是有些弄不懂为什么这里要这么写:
for(i=n-1,j=0;i>=0,j<n;i--,j++)
同时,如果程序不能够申请第二个数组的空间,即不允许增加空间,只允许在第一个上操作呢?怎么修改呢?谢谢!
nice90 2004-11-10
  • 打赏
  • 举报
回复
没有达到逆序的效果。
micro1984 2004-11-10
  • 打赏
  • 举报
回复
谢谢 woshi_zjf()
micro1984 2004-11-10
  • 打赏
  • 举报
回复
谢谢楼上这位大哥
wdy0725 2004-11-10
  • 打赏
  • 举报
回复
# include <stdio.h>

void main()
{
char *arr[100]=0;
int i=0;
printf("Please Input: ");
getch(*arr);
while(*arr[i]!='\0'&&i<20)
getch(*arr[++i]);
while(--i>=0)
printf("%d",*arr[i]); //可能有错误,谢谢指出。
}
woshi_zjf 2004-11-10
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *x;
int *y;
int i,j,n;
puts("please enter number of elements in the array: ");
scanf("%d",&n);
x=(int *)calloc(n,sizeof(int));
y=(int *)calloc(n,sizeof(int));
if(x!=NULL)
{
for(i=0;i<n;i++)
{
printf("plese enter %d number: ",i+1);
scanf("%d",x+i);
}
for(i=n-1,j=0;i>=0,j<n;i--,j++)
y[j]=x[i];
for(i=0;i<n;i++)
printf("%d number is %d\n",i,*(y+i));
free(x);
free(y);
return 0;
}
else
{
puts("not enough memory!");
return 1;
}

}
zhangfjj 2004-11-10
  • 打赏
  • 举报
回复
定义一个指针数组
输入不定的整数,
这个你说得不清楚!其他好办!

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧