Page 1 of 1

Test for Backend C : Factorial

Posted: Thu Jun 02, 2022 5:15 pm
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 !

Re: Test for Backend C : Factorial

Posted: Thu Jun 02, 2022 11:04 pm
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

Re: Test for Backend C : Factorial

Posted: Fri Jun 03, 2022 12:13 am
by threedslider
Yes, you are right about that, thank you @jack.