Computer Science, asked by ananyakohligrm, 1 year ago

Standard Programming
Advanced Programm
Question Type MCO
Question No.3
Eesha wrote a function fact() in "C" language to calculate factorial of a given number and saved the file as factc. She forgot to code a main function to call this fact function. Will she be able
to compile this fact.c without the main() function?​

Answers

Answered by qwtiger
0

Answer:

The Answer is No. She will not be able to compile the fact.c without the main() function. Because the main() function is needed to compile any kind of C program.

The program should be:

It can be done using the recursion.

Solution:

#include<stdio.h>

long fact(int);  

int main()

{

 int n;

 long f;

printf("Enter an integer to find its factorial\n");

 scanf("%d", &n);  

 if (n < 0)

   printf("Factorial of negative integers isn't defined.\n");

 else

 {

   f = factl(n);

   printf("%d! = %ld\n", n, f);

 }

 

 return 0;

}

 

long fact(int n)

{

 if (n == 0)

   return 1;

 else

   return(n * fact(n-1));

}

Similar questions