codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <stdio.h> #include <math.h> #include <iostream> #include <cmath> using namespace std; int main(void) { int amplitude = 1; int frequency = 1; int phase = 0; int start_time = 0; int end_time = 1; double f, t; printf("input the amplitude = %d\n", amplitude); printf("input the frequency= %d\n", frequency); printf("input the phase in radian= %d\n", phase); printf("input the start time= %d\n", start_time); printf("input the end time= %d\n", end_time); // printf("==============================================================\n"); cout<<setfill('='); cout<<setw(60)<<"="<<endl; printf(" x sin(x) value sin(x) graph \n"); printf("==============================================================\n"); printf(" -1-------------------0-------------------1\n"); cout.precision(2); cout.setf(ios::fixed); cout.setf(ios::right); //cout.setf(ios::showpos); for(t = start_time; t <= end_time; t+=0.05) { f = amplitude*sin(2*M_PI*frequency*t+phase); // printf("%.2f %+.2f %*c\n", t, f,30-(int)(f*20),'*'); cout<<t<<setw(8)<<f<<setw(30-(int)(f*20))<<"*"<<endl; } printf("==============================================================\n"); return 0; }
Private
[
?
]
Run code