急 急 急 C语言问题 求高手来解决 答对再加分!!

1.用指针编程序将a数组中的n个整数按输入时的相反顺序排列.
2.编写一个程序,输入一个字符存放在一个字符数组中,并输入处理后的所有字符.子函数把所有空格和数字移出.
3.编写函数int find(int *p,int n,int x),在指针p所指的数组中查找整型数x,如果x在数组中,则该函数返回0.n为数组的大小.

1.

//---------------------------------------------------------------------------

#include <stdio.h>

typedef int data_type;
void fun(data_type *a,int n)
{
data_type t,*b=a,*e=a+n-1;
while (b<e)
{
t=*b;
*b=*e;
*e=t;
++b;
--e;
}
}
int main(void)
{
data_type a[6];
int i;
for (i = 0; i<6; i++) scanf("%d",a+i);/*输入数组元素*/

for (i = 0; i<6; i++) printf("%d\t",a[i]);/*输出原始情况*/

fun(a,6); /*逆置数组元素*/

for (i = 0,putchar('\n'); i<6; i++) printf("%d\t",a[i]);/*输出逆置后的数组*/

return 0;
}
//---------------------------------------------------------------------------

2.
//---------------------------------------------------------------------------

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

void fun(char *a)
{
int i,j;
for (i = 0; a[i]; ) {
if (isspace(a[i])||isdigit(a[i]))
for (j=i; a[j]; ++j) {
a[j]=a[j+1];
}
else i++;
}
}
int main(void)
{
char str[80];
scanf("%79[^\n]",str);/*输入一个字符串,最长为79个字符,以回车结束输入*/
printf("%s\n",str);/*输出处理之前的字符串*/
fun(str); /*进行去除空格、数字的处理*/
printf("%s\n",str);/*输出处理之后的字符串*/
return 0;
}
//---------------------------------------------------------------------------

3.
//---------------------------------------------------------------------------

#include <stdio.h>

int find(int *p,int n,int x) /*如果在长度为n的整型数组p中找到了整数x,则返回0,否则返回1*/
{
int i;
for (i = 0; i<n; i++) {
if (p[i]==x) {
return 0;
}
}
return 1;
}
int main(void)
{
int a[5],i,x;
for (i = 0; i<5; i++) {
scanf("%d",a+i);
}
printf("输入一个要查找的整数:");
scanf("%d",&x);
if (find(a,5,x)) {
printf("%d不在这个数组中!\n",x);
}
else printf("%d在这个数组中!\n",x);
return 0;
}
//---------------------------------------------------------------------------
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-11-06
#include <stdio.h>

int find(int *p,int n,int x)
{
while (n-->0) {
if (*p == x)
return 0;
}
return -1;
}

int main(int argc, char* argv[])
{

/*
//这里是第一题
int buf[20];
int n=0;
int index=0;
int temp;

while (n<20) {
scanf("%d", &buf[n++]);
}
n--;
while (index < n/2) {
temp = buf[index];
buf[index] = buf[n-index];
buf[n-index] = temp;
index++;
}
*/

/*
//这个是第二题
int num =0;
char buf[20];
char *src;
char *des;
int src_num = 0;

while (num < 20) {
scanf("%c", &buf[num++]) ;
}
des= buf;
src = buf;
while (src_num++ < num) {
if (!(*src == ' ' || *src >='0' && *src <= '9')) {
*des++ = *src++;
}
else {
*src++;
}
}
*des = '\n';
*/

/*这里是第三题*/
int n = 0;
int m = -1;
int buf[20];
while (n<5) {
scanf("%d", &buf[n++]);
}
m=find(buf, n, 10);
getchar();
return 0;
}
相似回答