#include
// 輸入大於2的正整數求小於n的質數
int main(void) {
int n,i,j,count,count1;
count = 0;
count1 = 0;
scanf("%d",&n);
if(n<2 br=""> {
printf("2>輸入數字小於2條件不合,");
}
printf("小於%d的質數有:\n",n);
for(i=2;i<=n;i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
if(n%i==0)
{
printf("[%d],",i);
count1++;
}
else
{
printf("%d,",i);
}
count++;
}
}
printf("質數共%d個\n",count);
printf("[質因數]共%d個",count1);
return 0;
}
//
int main(void) {
int n,i,j,count,count1;
count = 0;
count1 = 0;
scanf("%d",&n);
if(n<2 br=""> {
printf("2>輸入數字小於2條件不合,");
}
printf("小於%d的質數有:\n",n);
for(i=2;i<=n;i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
if(n%i==0)
{
printf("[%d],",i);
count1++;
}
else
{
printf("%d,",i);
}
count++;
}
}
printf("質數共%d個\n",count);
printf("[質因數]共%d個",count1);
return 0;
}
0 意見:
張貼留言