Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- int x;
- int check();
- printf("請輸入一個數字\n");
- scanf("%d",&x);
- if (check(x)==0)
- {
- printf("x=%d\n為質數\n",x);
- }
- else
- {
- printf("x=%d\n非質數\n",x);
- }
- printf("============================\n");
- system("pause");
- return 0;
- }
- int check(int a)
- {
- int i,count=0;
- for(i=2;i<a;i++)
- {
- if (a%i==0)
- {
- count=count+1;
- }
- }
- return(count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement