编程练习:
/*编写一个杨辉三角的数组*/
#include <stdio.h>
int main()
{
int n;
int i = 0;
int j = 0;
int a[100][100];
printf("please input n:\n"); //输入输入的行数
scanf("%d",&n);
for (i = 0;i < n ;i++)
{
for (j = 0;j < i+1;j++)
{
if(j==i||j==0)
{
a[i][j]=1;
}
else
{
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}
}
for(i = 0;i < n;i++)
{
for(j=0;j<i+1;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
2.删除一串字符串中指定的子串
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[20];
char *p=a;
char *q;
char *temp=(char*)malloc(sizeof(char)*20);
int i;
printf("please a:\n");
gets(a);
printf("please temp:\n");
gets(temp);
i=strlen(temp);
while((q=strstr(p,temp))!=NULL)
{
strcpy(q,q+i);
}
puts(p);
return 0;
}