Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Prime number using function in C

  1. #include<stdio.h>
  2. int check_prime(int);
  3. main()
  4. {
  5. int n, result;
  6. printf("Enter an integer to check whether it is prime or not.\n");
  7. scanf("%d",&n);
  8. result = check_prime(n);
  9. if ( result == 1 )
  10. printf("%d is prime.\n", n);
  11. else
  12. printf("%d is not prime.\n", n);
  13. return 0;
  14. }
  15. int check_prime(int a)
  16. {
  17. int c;
  18. for ( c = 2 ; c <= a - 1 ; c++ )
  19. {
  20. if ( a%c == 0 )
  21. return 0;
  22. }
  23. return 1;
  24. }
  25.