Advertisement
kk258966

4/23 c++練習四

Apr 23rd, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void)
  4. {
  5.    int x;
  6.    int check();
  7.    printf("請輸入一個數字\n");
  8.    scanf("%d",&x);
  9.    if (check(x)==0)
  10.    {
  11.               printf("x=%d\n為質數\n",x);
  12.    }
  13. else
  14.    {
  15.               printf("x=%d\n非質數\n",x);
  16.     }
  17.  
  18. printf("============================\n");
  19.  
  20.  
  21.     system("pause");
  22.     return 0;
  23. }
  24. int check(int a)
  25.  
  26. {
  27.     int i,count=0;
  28.     for(i=2;i<a;i++)
  29.     {
  30.                     if (a%i==0)
  31.                     {
  32.                        count=count+1;  
  33.                     }
  34.                    
  35.     }
  36.    
  37.    
  38.     return(count);
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement