Computer Science, asked by karankaushik22, 3 days ago

How can you say that c uses modular approach,why it is advantageous ?WAP of factorial using this approach?​

Answers

Answered by samarthkrv
0

Answer:

#include <stdio.h>

int main() {

   int fact = 1 , num , i;

   printf("Enter a numer:");

   scanf("%i" , &num);

       for(i = 0; i < num; i++)

           {

               fact = fact * (i+1);

           }

           printf("Factorial of %i is %i" , num , fact);

   

   return 0;

}

Explanation:

Answered by deepakpandit11
1

Answer:

C is called a structured programming language because to solve a large problem, C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility. The program which solves the entire problem is a collection of such functions.

Module is basically a set of interrelated files that share their implementation details but hide it from the outside world. How can we implement modular programming in c? Each function defined in C by default is globally accessible. This can be done by including the header file in which implementation of the function is defined.

Suppose, we want to declare a Stack data type and at the same time want to hide the implementation, including its data structure, from users. We can do this by first defining a public file called stack.h which contains generic data Stack data type and the functions which are supported by the stack data type.

In the header file we must include only the definitions of constants, structures, variables and functions with the name of the module, that makes easy to identify source of definition in a larger program with many modules.

Keywords extern and static help in the implementation of modularity in C.

Similar questions