Test for Backend C : Factorial

Share your advanced PureBasic knowledge/code with the community.
threedslider
Enthusiast
Enthusiast
Posts: 397
Joined: Sat Feb 12, 2022 7:15 pm

Test for Backend C : Factorial

Post by threedslider »

An old code I made for a test in Backend C with Purebasic 6 Beta.

Code: Select all

; printf under PB_C
CompilerIf #PB_Compiler_ExecutableFormat<>#PB_Compiler_Console 
  CompilerError "Exec-Format must be Console in Compiler-Option"
CompilerEndIf  

;! int fact(int);

! int fact(int n) {
!   if(n>=1) 
!     return n*fact(n-1); 
!   else return 1; 
! }

OpenConsole()
! int number;
! printf("Enter a positive integer: ");
! scanf("%d",&number);
! printf("Factorial of %d = %d", number, fact(number));
Input()
CloseConsole()
Hope that work for you :D

Happy coding !
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Test for Backend C : Factorial

Post by jack »

nice example but I would add

Code: Select all

CompilerIf #PB_Compiler_Backend<>#PB_Backend_C
  CompilerError "Compiler_Backend must be C in Compiler-Option"
CompilerEndIf
threedslider
Enthusiast
Enthusiast
Posts: 397
Joined: Sat Feb 12, 2022 7:15 pm

Re: Test for Backend C : Factorial

Post by threedslider »

Yes, you are right about that, thank you @jack.
Post Reply