高级语言程序设计第八次作业
这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/gjyycx
这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/gjyycx/homework/15590
学号:102500417
姓名:刘朝榕
编程练习11.13
1.

。
。
。
2.

。
。
。
3.

。
。
。
6.

。
。
。
7.

。
。
。
编程练习12.9
1.

。
。
。
2.




。
。
。
3.




。
。
。
8.>
点击查看代码
#include<stdio.h>
#include<stdlib.h>
int*make_array(int elem,int val){
int*shuzu=(int*)malloc(elem*sizeof(int));
if(shuzu!=NULL){
for(int i=0;i<elem;i++){
shuzu[i]=val;
}
}
return shuzu;
}
void show_array(const int ar[],int n){
for(int i=0;i<n;i++){
printf("%d ",ar[i]);
if((i+1)%8==0){
printf("\n");
}
}
printf("\n");
}
int main(void)
{
int * pa;
int size;
int value;
printf("Enter the number of elements: ");
while (scanf("%d", &size) == 1 && size > 0)
{
printf("Enter the initialization value: ");
scanf("%d", &value);
pa = make_array(size, value);
if (pa)
{
show_array(pa, size);
free(pa);
}
printf("Enter the number of elements (<1 to quit): ");
}
printf("Done.\n");
return 0;
}

。
。
。
9.
点击查看代码
#include<stdio.h>
#include<stdlib.h>
char**danci(int n){
char c;
while((c=getchar())==' ');
int i=0;
char**x=(char**)malloc(n*sizeof(char**));
if(x==NULL){
printf("内存分配失败");
return NULL;
}
while(i<n){
x[i]=(char*)malloc(100*sizeof(char*));
if(x==NULL){
printf("内存分配失败");
for(int j=0;j<i;j++){
free(x[j]);
}
free(x);
return NULL;
}
scanf("%s",x[i]);
i++;
}
return x;
}
int main(void){
int n;
printf("How many words do you wish to enter:");
scanf("%d",&n);
char**pa;
printf("Enter %d words now:\n",n);
pa=danci(n);
if(pa!=NULL){
printf("Here are your words:\n");
for(int i=0;i<n;i++){
printf("%s\n",pa[i]);
free(pa[i]);
}
free(pa);
}
}


浙公网安备 33010602011771号