Created
April 8, 2025 10:43
-
-
Save bonface221/b13d853d25ae6364a4caf11a2a8087b3 to your computer and use it in GitHub Desktop.
C program to calculate the area of a land. Write a C program that accepts the length and width of a rectangular piece of land in foot, converts them into meters and then calculates the area. The program shuould then output the length,width and area in metres. Use a function. Hint 1 foot = 0.3metres and area = length * width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
/* | |
Write a C program that accepts the length and width of a rectangular | |
piece of land in foot, converts them into meters and then calculates | |
the area. The program shuould then output the length,width and area in | |
metres. Use a function. Hint 1 foot = 0.3metres and area = length * width | |
*/ | |
double calcAreaInMetres(double length, double width) | |
{ | |
return (length * 0.3) * (width * 0.3); | |
} | |
int main() | |
{ | |
double length, width; | |
// Ask user for length | |
printf("Welcome to Land Area calculator\n"); | |
printf("--------------------------\n"); | |
printf("Enter the Lenght in foot\n"); | |
scanf("%lf", &length); | |
// Ask user for width | |
printf("Enter the width in foot\n"); | |
scanf("%lf", &width); | |
double result = calcAreaInMetres(length, width); | |
printf("Result %lf\n", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment