×
Reviews 4.9/5 Order Now

Distance Conversion Homework Solution using C Programming

July 10, 2024
Emily Johnson
Emily Johnson
🇺🇸 United States
C
Emily holds a bachelor's degree in software engineering and has completed over 700 orders in C homework help. Her expertise lies in memory management and file handling, making her the go-to expert for optimizing memory usage and seamlessly integrating file operations into C programs.
Key Topics
  • Question:
Tip of the day
Break your Python assignment into smaller tasks and test each part separately. Use meaningful variable names, write comments for clarity, and leverage built-in functions to simplify your code.
News
In 2025, JetBrains Fleet 2.0 introduced AI-powered code completion, while VS Code added advanced AI-driven bug detection and coding assistants, enhancing programming efficiency.

Question:

Write a C assignment program for a mile-to-kilometer conversion to run on ocelot. (1 Mile = 1.60934 Kilometers)

Create a nicely formatted chart with the conversions of each of the following values from Miles to Kilometers. There is no user input, these values can be constants in the program.

  • 2
  • 5.65
  • 300
  • 1845

Solution:

#include void convert(float miles[]){ float kilometeres[4]; for(int i=0; i < 4 ; ++i) { kilometeres[i] = miles[i] * 1.60934; //converts miles to Kilometeres } printf("Miles to Kilometeres chart using c.\n"); printf("____________________________________________________\n"); //design for printing chart printf("| Miles | Kilometeres |\n"); printf("----------------------------------------------------\n"); for(int i =0 ; i < 2; i ++) { printf("| %.5f | %.5f |\n", miles[i], kilometeres[i]); } printf("| %.5f | %.5f |\n", miles[2], kilometeres[2]); printf("| %.5f | %.5f |\n", miles[3], kilometeres[3]); printf("----------------------------------------------------"); } int main() { // Declaring an array of input values provided float miles[4] = {2.0, 5.65, 300, 1845}; // An array to store kilometer values, once converted float kilometers[4]; for(int i=0; i < 4 ; ++i) { // Conversion of miles to kilometers kilometers[i] = miles[i] * 1.60934; } // Displaying the information in a table printf("\t CONVERTING MILES\n"); printf("%15s%15s\n", "Miles", "Kilometers"); for(int i=0; i < 4 ; ++i) { printf("%15.5f%15.5f\n", miles[i], kilometers[i]); } return 0; }

Output:

Convert Miles

Related Samples

Explore our collection of free C programming samples showcasing practical solutions and examples. Discover efficient coding techniques and best practices tailored to enhance your programming skills. Dive into our comprehensive library today!