DSA 1.25 : procedural programming using structure and functions

PHOTO EMBED

Tue Mar 07 2023 15:32:57 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

#include <iostream>
using namespace std;

struct rectangle
{
    int length;
    int breadth;
};

void initialize(struct rectangle *r, int l, int b)
{
    r->length = l;
    r->breadth = b;
}

int area(rectangle r)
{
    return r.length*r.breadth;
}

int perimeter(rectangle r)
{
    int p = 2*(r.length*r.breadth);
    return p;
}

int main() 
{
    rectangle r={0,0};
    int l,b;
    cout << "Enter length and breadth : ";
    cin >> l >> b;
    initialize(&r,l,b);
    
    int a = area(r);
    cout <<"Area is : "<<a << endl;
    
    int peri = perimeter(r);
    cout <<"perimeter is :"<<peri;

    return 0;
}
}
content_copyCOPY

this approach isprocedural programming approach which also uses structures along with functions.