Pregunta
upstudy study bank question image url

  1. Write a C-program to input two initials of your name, your height in inches and weigh
    stones; convert the height to centimetres and weight to kilograms and display the follow
    results.
    PERSONAL DETAILS
    AGRIC
    IDENTIFICATION: BH
    HEIGHT (cm): 180
    WEIGHT (Kg): 75
    Tote: 1 inch 2.54 cm and 1 stone
  1. Convert a temperature reading in degrees Fahrenheit to degrees Celsius, using the formul
    C = (5/9) * (F-32).
    Test the program with the following values: (degrees Fahrenheit)

Ask by Warren Murray. in Nigeria
Dec 12,2024

Solución de inteligencia artificial de Upstudy

Respuesta verificada por el tutor

Responder

The C program takes initials, height in inches, and weight in stones, converts them to centimeters and kilograms, and displays the results. It also converts Fahrenheit temperatures to Celsius and displays them.

Solución

Below is a C program that accomplishes the tasks you’ve described. It takes two initials, height in inches, and weight in stones as input, converts the height to centimeters and weight to kilograms, and then displays the results. Additionally, it converts a list of Fahrenheit temperatures to Celsius.
#include <stdio.h>

#define INCH_TO_CM 2.54
#define STONE_TO_KG 6.364

void convert_and_display_personal_details() {
    char initial1, initial2;
    int height_in_inches;
    float weight_in_stones;

    // Input initials
    printf("Enter your initials (2 characters): ");
    scanf(" %c%c", &initial1, &initial2);

    // Input height in inches
    printf("Enter your height in inches: ");
    scanf("%d", &height_in_inches);

    // Input weight in stones
    printf("Enter your weight in stones: ");
    scanf("%f", &weight_in_stones);

    // Convert height to centimeters
    float height_in_cm = height_in_inches * INCH_TO_CM;

    // Convert weight to kilograms
    float weight_in_kg = weight_in_stones * STONE_TO_KG;

    // Display results
    printf("\nPERSONAL DETAILS\n");
    printf("IDENTIFICATION: %c%c\n", initial1, initial2);
    printf("HEIGHT (cm): %.2f\n", height_in_cm);
    printf("WEIGHT (Kg): %.2f\n", weight_in_kg);
}

void convert_fahrenheit_to_celsius() {
    float fahrenheit_values[] = {68, 150, 212, 0, -22, -200};
    int num_values = sizeof(fahrenheit_values) / sizeof(fahrenheit_values[0]);

    printf("\nFahrenheit to Celsius Conversion:\n");
    for (int i = 0; i < num_values; i++) {
        float celsius = (5.0 / 9.0) * (fahrenheit_values[i] - 32);
        printf("%.2f°F = %.2f°C\n", fahrenheit_values[i], celsius);
    }
}

int main() {
    convert_and_display_personal_details();
    convert_fahrenheit_to_celsius();
    return 0;
}

Explanation of the Code:

  1. Constants: The program defines constants for the conversion factors from inches to centimeters and stones to kilograms.
  2. Function convert_and_display_personal_details:
    • Prompts the user to enter their initials, height in inches, and weight in stones.
    • Converts height to centimeters and weight to kilograms.
    • Displays the personal details in a formatted manner.
  3. Function convert_fahrenheit_to_celsius:
    • Contains an array of Fahrenheit values to be converted.
    • Loops through the array, converts each value to Celsius using the provided formula, and prints the results.
  4. main function: Calls the two functions to execute the tasks.

How to Compile and Run:

  1. Save the code in a file named personal_details.c.
  2. Open a terminal and navigate to the directory where the file is saved.
  3. Compile the program using:
    gcc personal_details.c -o personal_details
    
  4. Run the program using:
    ./personal_details
    
You will be prompted to enter your initials, height, and weight, and then the program will display the converted values and the temperature conversions.

Respondido por UpStudy AI y revisado por un tutor profesional

error msg
Explicar
Simplifique esta solución

Extra Insights

Here’s a simple C program that meets your requirements:
#include <stdio.h>

int main() {
    // Initial variables
    char initials[3];
    float height_inches, height_cm;
    float weight_stones, weight_kg;
    float fahrenheit, celsius;

    // Input initials
    printf("Enter your initials: ");
    scanf("%s", initials);

    // Input height in inches
    printf("Enter your height in inches: ");
    scanf("%f", &height_inches);

    // Input weight in stones
    printf("Enter your weight in stones: ");
    scanf("%f", &weight_stones);

    // Conversions
    height_cm = height_inches * 2.54; // Convert height to cm
    weight_kg = weight_stones * 6.364; // Convert weight to kg

    // Display personal details
    printf("\nPERSONAL DETAILS\n");
    printf("IDENTIFICATION: %s\n", initials);
    printf("HEIGHT (cm): %.2f\n", height_cm);
    printf("WEIGHT (Kg): %.2f\n", weight_kg);

    // Temperature conversion
    float test_values[] = {68, 150, 212, 0, -22, -200};
    printf("\nTemperature Conversion from Fahrenheit to Celsius:\n");
    for (int i = 0; i < 6; i++) {
        fahrenheit = test_values[i];
        celsius = (5.0 / 9.0) * (fahrenheit - 32);
        printf("Fahrenheit: %.2f => Celsius: %.2f\n", fahrenheit, celsius);
    }

    return 0;
}

Additional Fun Facts:

The idea of converting height and weight into different units has historical roots – originally, different regions had unique systems of measurement! For instance, the stone is still commonly used in the UK for measuring body weight, harkening back to the days of trade when goods were literally weighed with stones!
In terms of real-world applications, this program helps you understand and manipulate everyday measurements. Whether it’s for an international travel plan or fitness tracking, converting units accurately can make a real difference! Plus, those temperature conversions remind us just how wide the range of climates is across the globe. Who knew cold could be this universal?

preguntas relacionadas

Latest Computer Technology Questions

¡Prueba Premium ahora!
¡Prueba Premium y hazle a Thoth AI preguntas de matemáticas ilimitadas ahora!
Quizas mas tarde Hazte Premium
Estudiar puede ser una verdadera lucha
¿Por qué no estudiarlo en UpStudy?
Seleccione su plan a continuación
Prima

Puedes disfrutar

Empieza ahora
  • Explicaciones paso a paso
  • Tutores expertos en vivo 24/7
  • Número ilimitado de preguntas
  • Sin interrupciones
  • Acceso completo a Respuesta y Solución
  • Acceso completo al chat de PDF, al chat de UpStudy y al chat de navegación
Básico

Totalmente gratis pero limitado

  • Solución limitada
Bienvenido a ¡Estudia ahora!
Inicie sesión para continuar con el recorrido de Thoth AI Chat
Continuar con correo electrónico
O continuar con
Al hacer clic en "Iniciar sesión", acepta nuestros términos y condiciones. Términos de Uso & Política de privacidad