| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1479 人关注过本帖
标题:[原创]如何实现写入100个实数并且又要调用100个实数做加法的程序
只看楼主 加入收藏
入门者
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2005-4-14
收藏
得分:0 
版主的程序值得借鉴! 3Q ~!

2005-05-06 08:47
musicml
Rank: 1
等 级:新手上路
帖 子:273
专家分:0
注 册:2005-4-2
收藏
得分:0 
不错!

Every thing is possible.
2005-05-06 23:31
musicml
Rank: 1
等 级:新手上路
帖 子:273
专家分:0
注 册:2005-4-2
收藏
得分:0 

//偶也写了个 //不是很好 //不过可以满足你的要求 //如何实现写入100个实数把这些数据存入date文件中, //并且在main()中调用这个date文件进行100个实数的算法,比如:做加法的程序

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

void writefile(int n); void addfile();

void writefile(int n) { int i; FILE *fp; int num; if((fp=fopen("date.txt","w"))==NULL) { printf("can not open the file!\n"); exit(1); } printf("please enter n numbers:\n"); for(i=0;i<n;i++) { printf("please enter th%d num:\t",i+1); scanf("%d",&num); fprintf(fp,"%d ", num); } fclose(fp); }

void addfile() { int num; int sum; FILE *fp; sum=0; if((fp=fopen("date.txt","r"))==NULL) { printf("can not enter this file!\n"); exit(1); } while(fscanf(fp,"%d",&num)!=EOF) { sum=sum+num; } printf("the result is :\t"); printf("sum=%d\n",sum); fclose(fp); }

int main() { int n; printf("please enter the n:\t"); scanf("%d",&n); writefile(n); addfile(); }


Every thing is possible.
2005-05-07 23:48
快速回复:[原创]如何实现写入100个实数并且又要调用100个实数做加法的程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013983 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved