给C语言程序加上注释

帮忙给每一行都加上注释 谢谢
第一个程序
#define X 10
#define Y 30
#define N 20
int A[N]={2,5,15,30,1,40,17,50,9,21,32,8,41,22,49,31,33,18,80,5};
#include<stdio.h>
void del(int *A, int *n, int x, int y)
{
int i,j;
for(i=j=0; i<*n; i++)
if(A[i]>y||A[i]<x)
A[j++]=A[i];
*n=j;
}
void output(int *A, int n)
{
int i;
printf("\n数组有%d个元素:\n",n);
for(i=0; i<n; i++){
printf("%7d",A[i]);
if((i+1)%10==0)
printf("\n");
}
printf("\n");
}
void main()
{
int n;
n=N;
output(A,n);
del(A,&n,X,Y);

output(A,n);
}

第二个程序
#include<stdio.h>
struct LinearList
{
int *list;
int size;
int MAXSIZE;
};
main()
{
int list1[15]={2,5,7,8,10,14,19,22,25,30};
int list2[15]={3,5,8,9,11,18,22,28,30,32,35};
int list3[30];
struct LinearList L1={list1,10,15};
struct LinearList L2={list2,11,15};
struct LinearList L3={list3,0,30};
int i,j,k;
for(i=j=k=0; k<L3.MAXSIZE&&i<L1.size&&j<L2.size; k++)
{
if(L1.list[i]>L2.list[j])
L3.list[k]=L2.list[j++];
else if(L1.list[i]==L2.list[j])
{
L3.list[k]=L1.list[i++];
j++;
}
else
L3.list[k]=L1.list[i++];
}
while(k<L3.MAXSIZE&&i<L1.size)
L3.list[k++]=L1.list[i++];
while(k<L3.MAXSIZE&&j<L2.size)
L3.list[k++]=L2.list[j++];
L3.size=k;
printf("合并后的数组长度是[%d]\n各元素如下:\n",L3.size);
for(k=0;k<L3.size;k++)
printf("%4d",L3.list[k]);
printf("\n");
return 0;
}

第一个程序 (/* */内为注释)
#define X 10 /* 定义X为10 */
#define Y 30 /* 定义Y为30 */
#define N 20 /* 定义N为20 */
int A[N]={2,5,15,30,1,40,17,50,9,21,32,8,41,22,49,31,33,18,80,5};/* 定义一个20位的数组A[N]并赋值 */
#include<stdio.h> /* 引用头文件stdio.h */
void del(int *A, int *n, int x, int y)/* 定义一个函数del,输入参数为int型的指针A,n和int型的x,y,作用是删去数组中大于x或小于y的数 */
{
int i,j;/* 定义整数型变量i,j */
for(i=j=0; i<*n; i++)/*循环,初始条件i=j=0,终止条件i<指针n的值,循环步长为1 */
if(A[i]>y||A[i]<x) /* 判断条件如果数组元素A[i]的值大于y或者小于x */
A[j++]=A[i]; /* 将数组元素A[i]赋值给数组元素A[j],然后j加1 */
*n=j; /* 给指针n赋值为j */
}
void output(int *A, int n)/* 定义函数output,输入参数为整型指针A和整型变量n,作用为输出数组前n个数 */
{
int i;/* 定义整型变量i */
printf("\n数组有%d个元素:\n",n);/* 在屏幕输出“数组有n个元素:”,(n为输入量或所赋值的量)*/
for(i=0; i<n; i++){ /* 循环,初始条件i=0,终止条件i<n,步长为1 */
printf("%7d",A[i]); /* 在屏幕输出数组A[i]的各个值 */
if((i+1)%10==0) /* 判断,条件为如果(i+1)除以10取余数等于0 */
printf("\n"); /* 在屏幕上输出换行 */
}
printf("\n");/* 在屏幕上输出换行 */
}
void main()/* 主程序 */
{
int n;/* 定义一个整型变量n */
n=N; /给n赋值为N,之前有定义N为20,所以实际n=20 */
output(A,n);/* 以数组A和n为参数,执行函数output */
del(A,&n,X,Y);/* 执行函数del */

output(A,n);/* 执行函数output */
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-09-21
第一个程序:
//---------------------------------------------------------------------------

#define X 10
#define Y 30
#define N 20 /*以上三句是定义了三个符号常量*/
int A[N]={2,5,15,30,1,40,17,50,9,21,32,8,41,22,49,31,33,18,80,5};
/*定义了一个全局变量整型数组A,长度是符号常量N的值,也就是20,并对数组进行了初始化*/
#include<stdio.h>/*包含头文件*/
void del(int *A, int *n, int x, int y) /*作用是删除A数组中小于y或者大于x的元素,并将没有删除的元素个数保存到n指向的变量中*/
{
int i,j;
for(i=j=0; i<*n; i++)
if(A[i]>y||A[i]<x)
A[j++]=A[i];
*n=j;
}
void output(int *A, int n)/*输出数组A中前n个元素*/
{
int i;
printf("\n数组有%d个元素:\n",n);
for(i=0; i<n; i++){
printf("%7d",A[i]);
if((i+1)%10==0)
printf("\n");
}
printf("\n");
}
void main()
{
int n;
n=N;
output(A,n);
del(A,&n,X,Y);

output(A,n);
}

//---------------------------------------------------------------------------

第二个程序:

//这个程序与归并排序有密切关系,建议除了看如下注释外,还应该着重研究一下归并排序算法,这样才能完全明白程序。
//---------------------------------------------------------------------------

#include<stdio.h>
struct LinearList /*定义一个结构体类型*/
{
int *list;
int size;
int MAXSIZE;
};
main()
{
int list1[15]={2,5,7,8,10,14,19,22,25,30};
int list2[15]={3,5,8,9,11,18,22,28,30,32,35};
int list3[30];
struct LinearList L1={list1,10,15};
/*定义一个LinearList类型的结构体变量,并将这个变量的list成员指针变量指向上面定义的list1数组,将成员变量size和MAXSIZE分别赋值为10和15*/
struct LinearList L2={list2,11,15};
struct LinearList L3={list3,0,30};
int i,j,k;

for(i=j=k=0; k<L3.MAXSIZE&&i<L1.size&&j<L2.size; k++) /*利用归并排序算法对list1数组和list2数组中的元素进行排序,并将结果保存到list3中*/
{
if(L1.list[i]>L2.list[j])
L3.list[k]=L2.list[j++];
else if(L1.list[i]==L2.list[j])
{
L3.list[k]=L1.list[i++];
j++;
}
else
L3.list[k]=L1.list[i++];
}

while(k<L3.MAXSIZE&&i<L1.size) /*将上述循环结束后,没有参与比较的list1和list2中的元素直接放在list3中*/
L3.list[k++]=L1.list[i++];
while(k<L3.MAXSIZE&&j<L2.size)
L3.list[k++]=L2.list[j++];
L3.size=k; /*k就是最终list3中元素的个数*/
printf("合并后的数组长度是[%d]\n各元素如下:\n",L3.size);
for(k=0;k<L3.size;k++) /*输出排序后的元素*/
printf("%4d",L3.list[k]);
printf("\n");
return 0;
}
//---------------------------------------------------------------------------本回答被提问者采纳