「Cでグラフ!」の編集履歴(バックアップ)一覧はこちら
「Cでグラフ!」(2010/12/14 (火) 22:07:13) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
#include <stdio.h>
#include <math.h>
/* 任意の関数のグラフ */
double fun(double x)
{
double y;
y = sin(x);
return y;
}
int main(void){
double x, y;
double xfrom, xto;
int xsteps;
double yfrom, yto;
int xidx, yidx;
printf("*********\n");
printf("y=sin(x)\nx[rad]\n");
printf("*********\n");
printf("x: from to steps> ");
scanf( "%lf %lf %d", &xfrom, &xto, &xsteps );
printf("y: from to > ");
scanf( "%lf %lf", &yfrom, &yto );
for(xidx=0;xidx<=xsteps;xidx++){
x = xfrom + (xto-xfrom)/xsteps*xidx;
y = fun(x);
printf("%8.3lf: ",x);
if ((y<yfrom)||(y>yto)){
printf( "\n" );
}else{
yidx = (y-yfrom)*50/(yto-yfrom)+0.5;
while(yidx--){printf( " " );}
printf("*\n");
}
}
return 0;
}
#include <stdio.h>
#include <math.h>
/* 任意の関数のグラフ */
double fun(double x)
{
double y;
y = sin(x);
return y;
}
int main(void){
double x, y;
double xfrom, xto;
int xsteps;
double yfrom, yto;
int xidx, yidx;
printf("*********\n");
printf("y=sin(x)\nx[rad]\n");
printf("*********\n");
printf("x: from to steps> ");
scanf( "%lf %lf %d", &xfrom, &xto, &xsteps );
printf("y: from to > ");
scanf( "%lf %lf", &yfrom, &yto );
for(xidx=0;xidx<=xsteps;xidx++){
x = xfrom + (xto-xfrom)/xsteps*xidx;
y = fun(x);
printf("%8.3lf: ",x);
if ((y<yfrom)||(y>yto)){
printf( "\n" );
}else{
yidx = (y-yfrom)*50/(yto-yfrom)+0.5;
while(yidx--){printf( " " );}
printf("*\n");
}
}
return 0;
}
----