回覆列表
  • 1 # 匠工加工網

    #include <stdio.h>

    #include <stdlib.h>

    /*

    Enter a positive integer between 2 and 1000000: [11]

    The number 11 is a prime.

    Enter a positive integer between 2 and 1000000: [24]

    The number 24 is not a prime.

    */

    int main()

    {

    printf("Enter a positive integer between 2 and 1000000: [");

    int x,i,flag;

    flag = 0;

    scanf("%d",&x);

    printf("]\n",x);

    for(i =2;i<=x/2;i++)

    {

    if(x%i==0)

    {

    flag = 1;

    break;

    }

    }

    if(flag == 0)

    {

    printf("The number %d is a prime",x);

    }

    else

    {

    printf("The number %d is not a prime\n%d=",x,x);

    int temp,m;

    temp = x;

    m = 2;

    while(temp!=m)

    {

    if(temp%m==0)

    {

    printf("%dx",m);

    temp/=m;

    }

    else

    m++;

    }

    printf("%d\n",m);

    }

    return 0;

    }

  • 中秋節和大豐收的關聯?
  • 闌尾炎可以吃辣椒嗎?