Warning: fopen(/www/wwwroot/www.wendadaohang.com/data/md5_content_title/f8/f807b7453ba4546cce5f27182170ab8b.txt): failed to open stream: No space left on device in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2468

Warning: flock() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2469

Warning: fclose() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2475
一维数组的查找,用C语言写。 - 00问答网

一维数组的查找,用C语言写。

从数据文件读入若干整数值到数组,在数组中删除指定的数(该数键盘输入),处理后的数组元素再写入另一个数据文件。输出反馈,删除成功还是失败。要求自定义以下函数:
(1)功能函数int del(int arr[],int n,int i):在有n个整数的数组arr中删除下标为i的数组元素,返回删除后的实际元素个数。
(2)功能函数int find(int arr[],int n,int x) :寻找值为x的数组元素,找到返回下标值,找不到返回-1。
(3)功能函数 int getData(int arr[]):从文本文件data.txt读取数据到数组arr,返回读取的元素个数。
(4)功能函数int saveData(int arr[],int n) :将数组arr的数据写入文本文件result.txt,成功返回1,否则返回0。
(5)主函数:调用以上函数完成功能。输出反馈,删除成功还是失败。(说明:可以只删除找到的第一个数)

#include <stdio.h>
#include <stdlib.h>

void main()
{
int i,f;
long int a[20]={2,4};
for(i=2;i<20;i++)
a[i]=a[i-1]+2;
while(1)
{
printf("输入元素号:");
scanf("%d,",&f);
if(f<=21&&f>=1)
printf("元素的数值:%d\n",a[f-1]);
else
printf("超出数组范围\n");
}
system("pause");
}//看看符合不符
温馨提示:答案为网友推荐,仅供参考
相似回答