#include<stdio.h>#include<stdbool.h>//使用stdbool.h头文件使用布尔型_bool来替代_Bool类型。//用TRUE与FALSE分别带替0与1来进行简单的判断intmain(void){unsignedlong num;//带测试的约数unsignedlong div;//可能的约数
bool isPrime;//素数的标记printf("please enter an integer for analysis;\n");printf("Enter q to quit.\n");//scanf("%lu",&num);while(scanf("%lu",&num)==1)//这是是进行判断,判断是否有输入,如果有输入//如果判断有数输入,那么就会进行这个循环,否则就跳出循环输出Bye{for(div=2,isPrime=true;div*div<=num;div++){if(num%div ==0){if((div*div)!=num){printf("%lu is divisible by %lu and %lu.\n",num,div,num/div);}elseprintf("%lu is divisible by %lu./n",num,div);
isPrime = false;//该数不是素数}}if(isPrime){printf("%lu is prime.\n",num);//该数是素数}printf("please enter an integer for analysis;\n");printf("Enter q to quit.\n");}printf("Bye\n");return0;}