modular programming in C programming Language

  Modular Programming Structure in C programming.
Let understand the modular programming from the Given Diagram .
Modern software systems typically consist of several modules that must interact to each other correctly in order to work properly.
Different components of a software system are divided into separate functional units called Modularity.
From the Given fig. we can observer that the Main program is a group of several modules.
Each module does a well-defined task and the modules may call to one-another as needed. The main program .
The main program is divided into three module module-1,module-2 and module-3. where as module-1 is again divided in module-4 and module-5.
Each modules performs their unique individul task and may communicate to each other. Modules makes program easy to test,debug and maintain.
Every module has it own specific task and can be use repeatedly in the program when ever required. Repeate use of module reduce program size and maintainability.Repeated use of module reduce program size and maintainability.
Module is seperate independent function code or program file that can be reuse in the progam.
for e.g header files
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

Program to Calculate the area and circumference of a circle Using Module in C programming.

We want to create a program that calculates the area and circumference of a circle. We can break down the functionality into two modules: one for calculating the area of circle and another for calculating the circumference of a circle.

First, we create a header file called "rectangle.h" which contains the function prototypes: c

create a header file called "circle.h" which contains the function prototypes:

  // circle.h
  #ifndef CIRCLE_H
  #define CIRCLE_H
  double calculateArea(double radius);
  double calculateCircumference(double radius);
  #endif


Next, we create a source file called "circle.c" which contains the implementations of the functions:

  // circle.c
  #include "circle.h"
  double calculateArea(double radius) {
     return 3.14*radius*radius;
  }
  double calculateCircumference(double radius) {
     return 2 * 3.14*r;
  }

Finally, in our main program we include the "circle.h" header file and use the functions from the "circle.c" module:

// main.c
  #include <stdio.h>
  #include "circle.h"
  int main()
    {
    double r = 5.0;
   double area = calculateArea(r);
   double cirF = calculateCircumference(r);
   printf("Area of Circle= %.2f\n", area);
   printf("Circumference of Circle= %.2f\n", cirF);
    return 0;
  }
 Output:
 Area of Circle=78.50
 Circumference of Circle=31.40


Previous Topic:-->> Multiple Function Program in C || Next topic:-->>Elements of user Defined Function in C.
Other Topics: