This type of preprocessor directive tells the compiler to include a file in the source code program.
- There are two ways of the file inclusion statement:
- If the first way is used, the file and then the filename in the current working directory and the specified list of directories would be searched.
- If the second way, is used the file and then the filename in the specified list of directories would be searched.
i) #include “file-name”
ii) #include <file-name>
Example
file name - file.c
#include<stdio.h>
#include "fact.h"
#include<conio.h>
int main()
{
int n,fact;
printf("Enter the value of n :");
scanf("%d",&n);
fact = factorial(n);
printf("\n Factorial of %d is %d",n,fact);
getch();
return 0;
}
File name - fact.h
#include<stdio.h>
int factorial (int n)
{
int i,f = 1;
for(i=1;i<=n;i++)
{
f = f * i;
}
return f;
}
Output
Enter the value of n : 6
Factorial of 6 is 120
No comments:
Post a Comment