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

int main(int argc,char**argv)
{
	double d,m=0,s=0,t;
	char*np;
	/*check argc*/
	if(argc<2||argc>4){
		fprintf(stderr,"Usage: %s degree [minutes [seconds]]\n",*argv);
		return 1;
	}
	/*convert to float*/
	d=strtod(argv[1],&np);
	if(*np){
		fprintf(stderr,"Degree parameter is not a floating point number.\n");
		return 1;
	}
	if(argc>2){
		m=strtod(argv[2],&np);
		if(*np){
			fprintf(stderr,"Minutes parameter is not a floating point number.\n");
			return 1;
		}
	}
	if(argc>3){
		s=strtod(argv[3],&np);
		if(*np){
			fprintf(stderr,"Seconds parameter is not a floating point number.\n");
			return 1;
		}
	}
	/*convert to degree only*/
	d+=m/60.0+s/3600.0;
	printf("degrees: %.5lf deg\n",d);
	/*convert to degree plus minutes*/
	t=floor(d);
	m=(d-t)*60.0;d=t;
	printf("minutes: %.0lf deg %06.3lf'\n",d,m);
	/*convert to seconds*/
	t=floor(m);
	s=(m-t)*60.0;m=t;
	printf("seconds: %.0lf deg %02.0lf' %04.1lf\"\n",d,m,s);
	return 0;
}
