fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. long songuyento;
  5. printf("Moi nhap so nguyen to : ");
  6. scanf("%ld",&songuyento);
  7.  
  8. if(isPrimeNumber(songuyento)){
  9. printf("La so nguyen to");
  10. }
  11. else{
  12. printf("Khong la so nguyen to");
  13. }
  14. return 0;
  15. }
  16. //tra ve 1 neu dau vao la so nguyen to, tra ve 0 neu dau vao k phai la so nguyen to
  17. int isPrimeNumber(long a){
  18. if(a==0 || a==1) return 0;
  19. else if(a==2|| a==3) return 1;
  20. else{
  21. long b = (long)sqrt(a);//trong 1 chuong trinh kiem tra so nguyen t thi chi can kiem tra tu 2 -> can bac 2 cua so do
  22. for(long i=2; i <b ; i++){
  23. if(a % i == 0) // Neu a chia het cho i tuc la a k phai so nguyen to
  24. return 0;
  25. }
  26. else{
  27. return 1;
  28. }
  29. }
  30. }
  31. }
  32.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:8:2: warning: implicit declaration of function 'isPrimeNumber' [-Wimplicit-function-declaration]
  if(isPrimeNumber(songuyento)){
  ^
prog.c: In function 'isPrimeNumber':
prog.c:21:3: warning: implicit declaration of function 'sqrt' [-Wimplicit-function-declaration]
   long b = (long)sqrt(a);//trong 1 chuong trinh kiem tra so nguyen t thi chi can kiem tra tu 2 -> can bac 2 cua so do
   ^
prog.c:21:18: warning: incompatible implicit declaration of built-in function 'sqrt'
   long b = (long)sqrt(a);//trong 1 chuong trinh kiem tra so nguyen t thi chi can kiem tra tu 2 -> can bac 2 cua so do
                  ^
prog.c:22:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   for(long i=2; i <b ; i++){
   ^
prog.c:22:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
prog.c:26:4: error: 'else' without a previous 'if'
    else{
    ^
prog.c: At top level:
prog.c:31:1: error: expected identifier or '(' before '}' token
 }
 ^
stdout
Standard output is empty