#include "stdio.h" #include "math.h" #include "string.h" double Sigma=0; double Vin(double T){return (sin(T)+sin(2*T))/2;} int Comparator(){if(Sigma>=0) return 1; else return -1;} void Simulate(FILE* fp){ double T=0, DT=3.14159265358979/1024,V=0; int C; char str[512], sDT[10]; sprintf(str,"\n %7.4lf,%7.4lf",T, V); for(int i=1;i<=5096;i++){ C=Comparator(); sprintf(sDT,", %d", C); strcat(str,sDT); if(i%16==0){ fprintf(fp,str);sprintf(str,"\n %7.4lf,%7.4lf",T,V);} T+=DT;V=Vin(T);Sigma+=(V-C); } } int main(void){ FILE *fp=fopen("D:\\test.cv","wt"); Simulate(fp); fclose(fp); getchar(); }