谁能帮我分析一下这个C语言程序的每步的意思
#include<stdio.h>#defineN20fun(int*a,intn,intx){intp=0,i;a[n]=x;while(x!=a[p])p=p+1;i...
#include <stdio.h>
#define N 20
fun(int *a, int n, int x)
{
int p = 0, i;
a[n] = x;
while (x != a[p])
p = p+1;
if (p == n)
{
return -1;
}
else
{
/********found********/
for (i=p; i<n; i++)
a[i] = a[i+1];
return n-1;
}
}
main()
{
int w[N] = {-3, 0, 1, 5, 7, 99, 10, 15, 30, 90}, x, n, i;
n = 10;
printf("The original data:\n");
for (i=0; i<n; i++)
printf("%5d", w[i]);
printf("\nInput x (to delete):");
scanf("%d", &x);
printf("Delete :%d\n", x);
n = fun(w, n, x);
if (n == -1)
{
printf("***Not be found!***\n\n");
}
else
{
printf("The data after delete :\n");
for (i=0; i<n; i++)
printf("%5d", w[i]);
printf("\n\n");
}
} 展开
#define N 20
fun(int *a, int n, int x)
{
int p = 0, i;
a[n] = x;
while (x != a[p])
p = p+1;
if (p == n)
{
return -1;
}
else
{
/********found********/
for (i=p; i<n; i++)
a[i] = a[i+1];
return n-1;
}
}
main()
{
int w[N] = {-3, 0, 1, 5, 7, 99, 10, 15, 30, 90}, x, n, i;
n = 10;
printf("The original data:\n");
for (i=0; i<n; i++)
printf("%5d", w[i]);
printf("\nInput x (to delete):");
scanf("%d", &x);
printf("Delete :%d\n", x);
n = fun(w, n, x);
if (n == -1)
{
printf("***Not be found!***\n\n");
}
else
{
printf("The data after delete :\n");
for (i=0; i<n; i++)
printf("%5d", w[i]);
printf("\n\n");
}
} 展开
展开全部
#include <stdio.h>
#define N 20
fun(int *a, int n, int x) //传递一个数组首地址,一个n值 一个x值
{
int p = 0, i;
a[n] = x; //将数组的第n个赋值为x
while (x != a[p]) //判断数组从第一个数开始一直到结束 是否具有等于x值存在 如果不存在返回-1告知未找到 若存在则进else
p = p+1;
if (p == n)
{
return -1;
}
else
{
/********found********/
for (i=p; i<n; i++) //从发现位到结束位数据前移一位,则x值被覆盖
a[i] = a[i+1];
return n-1;
}
}
main() //该函数完成功能 首先定义一个数组 由用户手动输入一个x值 删除此数组中的与x值相等的位
{
int w[N] = {-3, 0, 1, 5, 7, 99, 10, 15, 30, 90}, x, n, i;
n = 10;
printf("The original data:\n");
for (i=0; i<n; i++)
printf("%5d", w[i]); //打印数组全部数据
printf("\nInput x (to delete):");
scanf("%d", &x); //输入x值
printf("Delete :%d\n", x);
n = fun(w, n, x); //调子函数
if (n == -1)
{
printf("***Not be found!***\n\n");
}
else
{
printf("The data after delete :\n");
for (i=0; i<n; i++)
printf("%5d", w[i]); //重新打印数据
printf("\n\n");
}
}
#define N 20
fun(int *a, int n, int x) //传递一个数组首地址,一个n值 一个x值
{
int p = 0, i;
a[n] = x; //将数组的第n个赋值为x
while (x != a[p]) //判断数组从第一个数开始一直到结束 是否具有等于x值存在 如果不存在返回-1告知未找到 若存在则进else
p = p+1;
if (p == n)
{
return -1;
}
else
{
/********found********/
for (i=p; i<n; i++) //从发现位到结束位数据前移一位,则x值被覆盖
a[i] = a[i+1];
return n-1;
}
}
main() //该函数完成功能 首先定义一个数组 由用户手动输入一个x值 删除此数组中的与x值相等的位
{
int w[N] = {-3, 0, 1, 5, 7, 99, 10, 15, 30, 90}, x, n, i;
n = 10;
printf("The original data:\n");
for (i=0; i<n; i++)
printf("%5d", w[i]); //打印数组全部数据
printf("\nInput x (to delete):");
scanf("%d", &x); //输入x值
printf("Delete :%d\n", x);
n = fun(w, n, x); //调子函数
if (n == -1)
{
printf("***Not be found!***\n\n");
}
else
{
printf("The data after delete :\n");
for (i=0; i<n; i++)
printf("%5d", w[i]); //重新打印数据
printf("\n\n");
}
}
展开全部
#include <stdio.h> // 把标准库文件stdio.h包含进来
#define N 20 // 定义了一个宏N 值为20
fun(int *a, int n, int x) // 声明并定义函数fun, 此处应加返回值类型int.参数: 一个整形指针, 两个整形
{
int p = 0, i;
a[n] = x;
while (x != a[p])
p = p+1;
if (p == n)
{
return -1;
}
else
{
/********found********/
for (i=p; i<n; i++)
a[i] = a[i+1];
return n-1;
}
}
main() // 函数执行入口
{
// 整形数组w, 初始化
int w[N] = {-3, 0, 1, 5, 7, 99, 10, 15, 30, 90}, x, n, i;
n = 10;
printf("The original data:\n"); // 标准打印函数
for (i=0; i<n; i++) // for 循环, 循环次数为10
printf("%5d", w[i]); // 打印
printf("\nInput x (to delete):"); // 打印
scanf("%d", &x); // 标准输入函数, 此为输入一个整形值
printf("Delete :%d\n", x); // 打印整型x的值, 输出到屏幕
n = fun(w, n, x); // 调用fun函数, 返回值赋值给n
if (n == -1) // if判断
{
printf("***Not be found!***\n\n"); // n为-1,则打印该句
}
else
{
printf("The data after delete :\n"); // n不为-1
for (i=0; i<n; i++) // for 循环, 次数10, 打印w的每个元素的值
printf("%5d", w[i]); // w[i]值, 由i指定
printf("\n\n"); // 打印出两个回车
}
}
#define N 20 // 定义了一个宏N 值为20
fun(int *a, int n, int x) // 声明并定义函数fun, 此处应加返回值类型int.参数: 一个整形指针, 两个整形
{
int p = 0, i;
a[n] = x;
while (x != a[p])
p = p+1;
if (p == n)
{
return -1;
}
else
{
/********found********/
for (i=p; i<n; i++)
a[i] = a[i+1];
return n-1;
}
}
main() // 函数执行入口
{
// 整形数组w, 初始化
int w[N] = {-3, 0, 1, 5, 7, 99, 10, 15, 30, 90}, x, n, i;
n = 10;
printf("The original data:\n"); // 标准打印函数
for (i=0; i<n; i++) // for 循环, 循环次数为10
printf("%5d", w[i]); // 打印
printf("\nInput x (to delete):"); // 打印
scanf("%d", &x); // 标准输入函数, 此为输入一个整形值
printf("Delete :%d\n", x); // 打印整型x的值, 输出到屏幕
n = fun(w, n, x); // 调用fun函数, 返回值赋值给n
if (n == -1) // if判断
{
printf("***Not be found!***\n\n"); // n为-1,则打印该句
}
else
{
printf("The data after delete :\n"); // n不为-1
for (i=0; i<n; i++) // for 循环, 次数10, 打印w的每个元素的值
printf("%5d", w[i]); // w[i]值, 由i指定
printf("\n\n"); // 打印出两个回车
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询