Monday, January 22, 2018

LG Online Code examination date : 19-1-2018

# include <stdio.H>
# include <conio.H>

/* Robot is at position 0 and move the robot to a destination x(x>0).
Robot moves in 1,2,3,4,5 steps.Find the minimum number of steps to reach
the destination.
Ex:destination x=12
output: 3 steps     */

main(){
int i,dist=13;
int steps[5]={1,2,3,4,5};
int moves;
clrscr();
for( i=sizeof(steps)/2-1 ; i>=0;i--)
{
if(dist%steps[i]==0)
{
printf("\n%d step of %d moves",steps[i],dist/steps[i]);
break;
}
else
{
moves=dist/steps[i];
dist=dist%steps[i];
if(moves!=0)
printf("\n%d step of %d moves",steps[i],moves);
}
}
}

No comments:

Post a Comment