// 09282009.cpp, P H Anderson, Sept 28, '09

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void print_binary(int v);

FILE *f1;

int main(void)
{
    float x, y;
    
    print_binary(31);
    print_binary(0);
    print_binary(251);    
    system("pause");
	
	f1=fopen("output.dta", "wt");
	if (f1 == NULL)
	{
       printf("Error in opening file");
       system("pause");
       exit(0);
    }
    else
    {
 	   for (int n=0; n<100; n++)
	   {
           x = 2.0 * M_PI *n/ 100;
           y = exp(-x)*cos(x);
	 	   printf("%f,%f\n", x, y);
		   fprintf(f1, "%f, %f\n", x, y); 
	   }
	   fclose(f1);   
    }   
    system("pause");
    system("type output.dta | more");
      
}

void print_binary(int v)
{
    int d, pow_2[8] = {1, 2, 4, 8, 16, 32, 64, 128};
    for (int n=7; n>=0; n--)
    {
        d = v / pow_2[n];
        v = v % pow_2[n];
        
        if (d==0)
        {
            printf("0");
        }
        else
        {
            printf("1");
        }
        
        if (n==4)
        {
            printf("_");
        }
    }
    printf("\n");
}