您的位置:首页 > 编程语言 > C语言/C++

C语言复习——数组、字符串

2017-04-12 22:19 316 查看
编程练习:

/*编写一个杨辉三角的数组*/
#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;

}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: