/* *program that accepts the longitude for a place and outputs the time difference from the zero meridian using putchar(). *author:rahule@cse.iitk.ac.in */ #include int main() { int deg,min,time; int hour,minute,total_time,total_minutes; char dir,a; int flag=0; int format_flag; deg=0; time=0; min=0; printf("\nenter the coordinates in the format ggdmm' :"); while((a=getchar())!='E'&&a!='e'&&a!='w'&&a!='W') //reads charecter till "e" or "w" and save it as "deg" { if(a>47&&a<58) { deg=deg*10+(a-'0'); //converts ASCII value to digit } else { flag=1; //for wrong inputs,flag is set break; } } dir=a; while((a=getchar())!='\'') //reads till " ' " { if(a>47&&a<58) { min=min*10+(a-'0'); //converts ASCII into number } else { flag=1; break; } } if(deg>180&&flag==0) { printf("\n wrong input \n"); printf("\n Degree needs to be less than 180"); flag=1; } if(min>60&&flag==0) { printf("\n wrong input \n"); printf("\n Minute needs to be less than 60"); flag=1; } if(flag==0) //if the input is in right format { total_minutes=deg*60+min; //converts coordinates into minutes total_time=total_minutes/15; //calculates total time in minutes hour=total_time/60; //converts minutes into hours minute=total_time%60; printf("\n Time "); //prints time as hh:mm if(dir=='w'||dir=='W') putchar('-'); putchar((hour/10)+48); putchar((hour%10)+48); putchar(':'); putchar((minute/10)+48); putchar((minute%10)+48); } else printf("\n Wrong input"); printf("\n"); }