Read Length, Width, Height
In this step, we will learn how to read the dimensions of a cuboid using C programming. We'll create a simple program that takes length, width, and height as input from the user.
First, let's create a new C file in the project directory:
cd ~/project
nano volume_cuboid.c
Now, let's write the code to read the dimensions:
#include <stdio.h>
int main() {
// Declare variables to store dimensions
float length, width, height;
// Prompt user to enter length
printf("Enter the length of the cuboid: ");
scanf("%f", &length);
// Prompt user to enter width
printf("Enter the width of the cuboid: ");
scanf("%f", &width);
// Prompt user to enter height
printf("Enter the height of the cuboid: ");
scanf("%f", &height);
// Print the entered dimensions
printf("Dimensions entered:\n");
printf("Length: %.2f\n", length);
printf("Width: %.2f\n", width);
printf("Height: %.2f\n", height);
return 0;
}
Let's compile and run the program:
gcc volume_cuboid.c -o volume_cuboid
./volume_cuboid
Example output:
Enter the length of the cuboid: 5
Enter the width of the cuboid: 3
Enter the height of the cuboid: 2
Dimensions entered:
Length: 5.00
Width: 3.00
Height: 2.00