The miles to kilometer converter program in c language include mathematical calculation as well as formatting of the output as table. The problem that is encountered in the program is formatting the output value as in table format and dividing both as an equal table. However, this problem is solved by a mathematical logic and successfully print in the console.
Program Code
#include
#include
float TableMilesToKM(float,float,int);
int main(int argc, char *argv[]) {
float start=1;
int increment =1;
printf(“Please enter the starting value: n”);
scanf(“%f”,&start);
printf(“Please enter the ending value: n”);
justify;”> scanf(“%f”,&stop);
printf(“Milest Kilometert Milest Kilometern”);
TableMilesToKM(start, stop, increment);
return 0;
}
float TableMilesToKM(float start, float stop, int increment)
{
float MileToKilo, MileToKilo2;
int split;
split=(start+stop)/2.0;
int i;
int indx;
for(i=start;i<=split;i++)
{
MileToKilo = i * 1.61;
MileToKilo2 = 1.61*(i – start + split + increment );
indx=i – start + split + increment;
printf(“%d t %.2f tt %d t %.2fn”, i, MileToKilo, indx, MileToKilo2);
}
}
Sample I/O 1: