#include <stdafx.h>
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;

float i;
float g;
char counter=20;
unsigned int it=0, top=0, tns=1, step=1;

void main ()
{

cout<<"Input number of pulses in half-wave: ";
cin>>it;
cout<<"\nInput top pwm value: ";
cin>>top;
cout<<"\nInput number of tables: ";
cin>>tns;
cout<<"\nInput step between tables: "; 
cin>>step;

top++;
g= (float) 3.141592654 / (it);
	
	ofstream out("s_table.txt");  

for(;tns;tns--)
{
	out<<'{';
	for (i=0;i<=it/2;i++)
	{
	out<<(unsigned int)(sin((float)i*g)*top);
	if (i!=it/2) out<<',';
	if (counter){counter--;} else {counter = 20; out<<'\n';}
	}
	out<<'}'<<'\n';
	if (tns>1) {out<<','<<'\n';}
	if (top>step) {top=top-step;}
	counter = 20;
}

out.close();

cout<<'\n'<<"please take result in s_table.txt"<<'\n';

}