bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_1 / assignment-primary / assignment-p-10.c

assignment-p-10.c (734B)


      1 /* Write a C program that defines a structure Rectangle with attributes length and width.
      2 Include a user-defined function named calculateArea with the signature float
      3 calculateArea(struct Rectangle r);. The function should calculate and return the area of
      4 the rectangle. */
      5 
      6 #include <stdio.h>
      7 
      8 struct Rectangle
      9 {
     10     float length;
     11     float width;
     12 };
     13 
     14 float calculateArea(struct Rectangle);
     15 
     16 int main()
     17 {
     18     struct Rectangle rec;
     19     printf("Enter the length of the Rectangle: ");
     20     scanf("%f", &rec.length);
     21     printf("Enter the width of the Rectangle: ");
     22     scanf("%f", &rec.width);
     23     printf("\nArea of the Rectangle = %g", calculateArea(rec));
     24 }
     25 
     26 float calculateArea(struct Rectangle r)
     27 {
     28     return r.length * r.width;
     29 }