okay, our mission is simple. How to make a set of data and put into a math function, calculate, and save the result in one file.
first of all built a simple linear graph function like y=mx+c, then, define all the coefficient. Then, built step by step.
1. put the header
2. define all the coefficient
3. built the input form
4. built the save data form
5. built the calculation function
thats all. the most important part here is to define the array "hairetsu" means the range of data. for example input x=1,2,3....till 100, we can write it
int i <<
double x1[1001] <<
then,
don`t forget to define x1[i] = x;
here is the script for this program
/*======================================================================linear graf data awis ver.File Name : 練習1.cVersion : 1.00Date : 2008.6.25Programed by awis85========================================================================*///------ヘッダー-------#include#include#include#include#include#include//-------変数定義--------int i; //parameterdouble x = 0.0; //X軸double y = 0.0; //Y軸double m = 0.0; //傾きdouble c = 0.0; //係数double x1[1001];double Y1[1001];//------データ入力と取り込み---------void input(void){printf("傾きを入力[1/cm]\n");scanf("%lf",&m);printf("\n");printf("定数を入力[cm]\n");scanf("%lf",&c);printf("\n");}//---データ保存---void save_data(void){char name[20];FILE *fp;printf("Input Data Name : ");scanf("%s",name);strcat (name,".dat");fp=fopen(name,"w"); //エラーメッセージif (fp==NULL){printf("File Cannot Open");exit(1);}for(i=0;i<= 100;i++){fprintf(fp,"%10.7f %10.7f\n",x1[i],Y1[i]);}fclose(fp);printf("出力終了 \n");}//----------計算ここから-----------void main(void){input();for(i=0;i<=100;i++){x = i * 1;y = (m * x) + c;x1[i] = x;Y1[i] = y;printf(" x= %lf y= %f \n",x,y);}printf("計算終了\n");save_data();}