rony-Rony_05

problem 5

Jul 2nd, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int check_prime(int);
  4.  
  5. main()
  6. {
  7.    int n, result;
  8.  
  9.    printf("Enter an integer to check whether it is prime or not.\n");
  10.    scanf("%d",&n);
  11.  
  12.    result = check_prime(n);
  13.  
  14.    if ( result == 1 )
  15.       printf("%d is prime.\n", n);
  16.    else
  17.       printf("%d is not prime.\n", n);
  18.  
  19.    return 0;
  20. }
  21.  
  22. int check_prime(int a)
  23. {
  24.    int i;
  25.  
  26.    for ( i = 2 ; i <= a - 1 ; i++ )
  27.    {
  28.       if ( a%i == 0 )
  29.      return 0;
  30.    }
  31.    return 1;
  32. }
Add Comment
Please, Sign In to add comment