学不过瘾?配套更多面试题讲解视频请移步下方直通车https://www.bilibili.com/video/BV1E34y1a7WP/
1.将数组a中n个整数按相反顺序存放
//数组方法
//思路 a[0]-a[9] a[1]-a[8] a[4]=a[5] a[]={1,2,3,4,5,6,7,8,9,10}
#include<stdio.h>
int main()
{
void fun(int x[],int n);
int i,a[10]={2,3,4,1,6,5,8,7,9,10};
printf("原来的数组\n");
for(i=0;i<=9;i++)
{
printf("%d\n",a[i]);
}
fun(a,10);
printf("现在的数组\n");
for(i=0;i<=9;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
void fun(int x[],int n)
{
int temp;
int i,j;
int m=(n-1)/2;
for(i=0;i<=m;i++)
{
j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;
}
return;
}
//用指针方式来实现
#include<stdio.h>
int main()
{
void fun(int *x,int n);
int i,a[10]={2,3,4,1,6,5,8,7,9,10};
printf("原来的数组\n");
for(i=0;i<=9;i++)
{
printf("%d\n",a[i]);
}
fun(a,10);
printf("现在的数组\n");
for(i=0;i<=9;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
void fun(int *x,int n)
{
int *p,temp,*i,*j,m=(n-1)/2;
i=x;j=x+n-1;p=x+m;
for(;i<=p;i++,j--)
{
temp=*i;*i=*j;*j=temp;
}
return ;
}
1.将数组a中n个整数按相反顺序存放https://www.bilibili.com/video/BV1uR4y1N7K5/
2.定义一个函数copy来实现字符串复制功能
//用字符数组名作为函数参
#include<stdio.h>
int main()
{
void copy(char a[], char b[]);
char a[]="abc";
char b[]="def";
printf("a数组 :%s\n b数组: %s\n",a,b);
copy(a,b);
printf("a数组 :%s\n b数组: %s\n",a,b);
return 0;
}
void copy(char a[],char b[])
{
int i=0;
while(a[i]!='\0')
{
b[i]=a[i];i++;
}
b[i]='\0';
}
//用字符型指针变量作为实参
#include<stdio.h>
int main()
{
void copy(char a[], char b[]);
char a[]="abc";
char b[]="def";
char *p1=a;
char *p2=b;
printf("a数组 :%s\n b数组: %s\n",a,b);
copy(p1,p2);
printf("a数组 :%s\n b数组: %s\n",a,b);
return 0;
}
void copy(char a[],char b[])
{
int i=0;
while(a[i]!='\0')
{
b[i]=a[i];i++;
}
b[i]='\0';
}
//用字符指针变量作形参和实参
#include<stdio.h>
int main()
{
void copy(char a[], char b[]);
char a[]="abc";
char b[]="def";
char *p1=a;
char *p2=b;
printf("a数组 :%s\n b数组: %s\n",a,b);
copy(p1,p2);
printf("a数组 :%s\n b数组: %s\n",a,b);
return 0;
}
void copy(char *p1,char *p2)
{
for(;*p1!='\0';p1++,p2++)
{
*p2=*p1;
}
*p2='\0';
}
2.定义一个函数copy来实现字符串复制功能https://www.bilibili.com/video/BV1PF411M7zT/
3.有两个整数a和b,由用户输入1,2,3,如输入1,就给出a和b中最大值,输入2,就给出a和b中最小值,输入3就给出a和b之和
#include<stdio.h>
int main()
{
int sun(int x,int y,int(*p)(int ,int));
int max(int,int);
int min(int,int);
int add(int,int);
int a=10;
int b=5;
int n;
printf("请输入1或2或3");
scanf("%d",&n);
if(n==1) sun(a,b,max);
else if(n==2) sun(a,b,min);
else if(n==3) sun(a,b,add);
return 0;
}
int sun(int x,int y,int(*p)(int,int))
{
int res;
res=(*p)(x,y);
printf("%d\n",res);
}
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
printf("max");
return(z);
}
int min(int x,int y)
{
int z;
if(x<y)z=x;
else z=y;
printf("min");
return(z);
}
int add(int x,int y)
{
int z;
z=x+y;
printf("add");
return(z);
}
3.有两个整数a和b,由用户输入1,2,3,如输入1,就给出a和b中最大值,输入2,就给出a和b中最小值,输入3就给出a和b之和https://www.bilibili.com/video/BV1hS4y1b78P/学不过瘾?配套更多面试题讲解视频请移步下方直通车https://www.bilibili.com/video/BV1E34y1a7WP/