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;
}
//---------------------------------------------------------------------------
温馨提示:内容为网友见解,仅供参考