lundi 30 octobre 2017

What is the reason why isn't this code running properly in C?

I am trying to learn C but my code is not running properly.It always gives fatal error.I think there is a problem in for loop.How can i fix it?

#include<stdio.h>
int main( void )
{
   int a  ;
   int b = 1 ;
   int i = 0 ;
   printf("Enter a number:");
   scanf("%d",&a);

   if(a=0)
       printf("Factorial=1");

   else if (a > 0){
       for(i=1 ; i<=a ;i++){
       b = 1;
       b *= i; 
       }
       printf("Factorial=%d",b);
   }     
   else  
       printf("FATAL ERROR");

return 0;
}

Aucun commentaire:

Enregistrer un commentaire