1.字符串连接
#include <stdio.h>
char* my_strcat(char* dest, char* src)
{
char* p = dest;
while (*dest)
{
++dest;
}
while (*dest++ = *src++)
;
return p;
}
int main(void)
{
//字符串连接
char str1[20] = "sdfed";
char str2[] = "dfgdfs";
printf("%s",my_strcat(str1, str2));
return 0;
}
2.字符串拷贝
#include <stdio.h>
char* my_strcpy(char* dest, char* src)
{
char* p = dest;
while (*dest++ = *src++)
;
return p;
}
int main(void)
{
//字符串拷贝
char str1[20] = "sdf";
char str2[] = "dfgf";
printf("%s",my_strcpy(str1, str2));
return 0;
}
3.杨辉三角
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void Yanghui(int n,int (*p)[20])
{
int m = n;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n - 1; j++)
{
printf(" ");
}
for (int j = 0; j < i + 1; j++)
{
if (i == j || j == 0)
{
*(*(p + i) + j) = 1;
}
else
{
//p[i][j] = p[i - 1][j] + p[i - 1][j - 1];
*(*(p + i) + j) = *(*(p + i - 1) + j) + *(*(p + i - 1) + j - 1);
}
printf("%d ", *(*(p + i) + j));
}
n--;
printf("\n");
}
}
int main(void)
{
int arr[20][20] = { 0 };
int n = 0;
printf("请输入打印的行数:\n");
scanf("%d", &n);
Yanghui(n, arr);
return 0;
}