Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

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 c;
25.
26. for ( c = 2 ; c <= a - 1 ; c++ )
27. {
28. if ( a%c == 0 )
29. return 0;
30. }
31. if ( c == a )
32. return 1;
33. }
34.

You might also like