[C] factor1.c -- It prompts the user to enter an integ →→→→→进入此内容的聊天室

来自 Wet Matamata, 2022-06-20, 写在 C, 查看 99 次.
URL http://www.code666.cn/view/a7241c5d
  1. /* factor1.c -- It prompts the user to enter an integer N. It prints out
  2.  *        if it is a prime or not. If not, it prints out all of its
  3.  *        proper factors.
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. int main(void) {
  9.   int n,
  10.     lcv,
  11.     flag; /* flag initially is 1 and becomes 0 if we determine that n
  12.              is not a prime */
  13.  
  14.   printf("Enter value of N > ");
  15.   scanf("%d", &n);
  16.   for (lcv=2, flag=1; lcv <= (n / 2); lcv++) {
  17.     if ((n % lcv) == 0) {
  18.       if (flag)
  19.         printf("The non-trivial factors of %d are: \n", n);
  20.       flag = 0;
  21.       printf("\t%d\n", lcv);
  22.     }
  23.   }
  24.   if (flag)
  25.     printf("%d is prime\n", n);
  26. }

回复 "factor1.c -- It prompts the user to enter an integ"

这儿你可以回复上面这条便签

captcha