11.10整理

有道云笔记

杨辉三角

#include <stdio.h>
#include "string.h"
void yh(int n,int (*p)[n]);
int main(int argc, const char *argv[])
{
	int n=0;
	scanf("%d",&n);
	int a[n][n];
	memset(a,0,sizeof(a));
	yh(n,a);
	return 0;
}
void yh(int n,int (*p)[n])
{
	int i=0,j=0;
	for(i=0;i<n;i++)
	{
		*(*(p+i)+0)=1;
		for(j=1;j<=i;j++)
			*(*(p+i)+j)=*(*(p+i-1)+j)+*(*(p+i-1)+j-1);

	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<=i;j++)
			printf("%d ",*(*(p+i)+j));
		printf("\n");
	}	
} 

字符指针

#include <stdio.h>
int main(int argc, const char *argv[])
{
	char *p[3]={"hello","world","sword"};//指向字符串常量,不能修改
	char a[]="qwertyu";
	char b[]="asdfdf";
	char c[]="zxcvbn";
	char *q[3]={a,b,c};                  //指向字符串数组,可以修改
	int i=0;
	for(i=0;i<3;i++)
		printf("%s ",*(p+i));
//	*(*(p+1)+2)='R';
	printf("%s",*(p+1));
	printf("\n");
	*(*(q+1)+2)='D';
	printf("%s\n",*(q+1));
	return 0;
}

简单使用数组指针

#include <stdio.h>
void output(int (*p)[2],int r,int l);
int main(int argc, const char *argv[])
{
	int a[2][2]={1,2,3,4};
	output(a,2,2);
	return 0;
}
void output(int (*p)[2],int r,int l )
{
int i=0,j=0;
for(i=0;i<r;i++)
{
	for(j=0;j<l;j++)
		printf("%d ",p[i][j]);
	printf("\n");
}
}

strcat实现

#include <stdio.h>
char *my_strcat(char *a,char *b);
int main(int argc, const char *argv[])
{
	char a[32]="124345";
	char b[32]="sdfghj";
	//	char *s=NULL;
	printf("%s\n",my_strcat(a,b));
	return 0;
}

char *my_strcat(char *a,char *b)
{
	int i=0;int j=0;
	while(*(a+i)!='\0')
		i++;
	while(*(b+j)!='\0')
	{
		*(a+i+j)=*(b+j);
		j++;
	}
	*(a+i+j)='\0';
	return a;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值