//題目:輸入一個大於3的整數n,判定它是否為素數(prime,又稱質數)
#include <stdio.h>
#include <math.h>
int main()
{int n,i,k;
printf("please enter a integer number,n=?");
scanf("%d",&n);
k=sqrt(n);
for(i=2;i<=k;i++)
if(n%i==0)break;
if(i<=k)printf("%d is not a prime number.\n",n);
else printf("%d is a prime number.\n",n);
return 0;
}
k=sqrt(n);
double sqrt (double);
#include <stdio.h> #include <math.h> int main( void ) { int p , n = 4 ; p = pow( 10 , n ); printf("%d\n", p ); return 0; }
k=sqrt(n);
for(i=2;i<=k;i++)
#include <stdlib.h> int main( void ) { int n ; printf("請輸入n的值\n"); scanf("%d",&n); if( n <= 3) printf("輸入不正確,程序退出\n"); else { int n_ = n , odd = 1 , k = 0 , i ; while( n_ >= odd ) { n_ -= odd ; odd += 2 ; k ++ ; } for(i=2;i<=k;i++) if(n%i==0) break; printf("%d%s是素數\n" , n , (i > k)?"":"不"); } return 0; }
while( n_ >= odd ) { n_ -= odd ; odd += 2 ; k ++ ; }