#include
#include
#include
void main()
{
clrscr();
int n;
int arr[100];
int curr_pos=0;
printf("Enter no of numbers; ");
scanf("%d",&n);
//int i;
//i=0;
for(int i=0;i<n;i++)
{
printf("Enter no " , i+1 , ": " );
scanf("%d",&arr[i]);
}
/* for(int j=0;j<n;j++)
{
printf("\n%d\n",arr[j]);
}*/
printf("\nEnter current position: ");
scanf("%d",&curr_pos);
int temp=curr_pos;
int total = 0;
for(int k=0;k<n;k++)
{
printf("%6d to %6d = %6d ms\n", temp, arr[k], abs(temp-arr[k]));
total = total + abs(temp-arr[k]);
temp = arr[k];
}
printf("\nTotal is : %d " , total);
getch();
}
No comments:
Post a Comment