cyg41223103 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • Brython
  • w15
    • Q2
    • Q1
  • 作業內容
    • W3
    • W4
    • w5
    • w6
      • 台灣國旗
      • 日本國旗
      • 美國國旗
      • 英國國旗
      • 韓國國旗
      • 中國國旗
    • W7
    • W10
    • W13
  • ANSI C
    • c1.
    • c2.
    • c3.
    • c4.
    • c5.
    • c6.
    • c7.
    • c8.
    • c9.
    • c10.
  • C_EX
    • ex1.
    • ex2.
    • ex3.
    • ex4.
    • ex5.
    • ex6.
    • ex7.
    • ex8.
    • ex9.
    • ex10.
  • NOTE
    • ssh
c1. << Previous Next >> c3.

c2.

檢查給定的數字是否為醜數

# include <stdio.h>
# include <string.h>

int main()
{
int n,x=0;
  printf("\n\n Check whether a given number is an ugly number:\n");
  printf("----------------------------------------------------\n");
  printf("Input an integer number: ");
  scanf("%d",&n);

      if (n <= 0) {  
            printf("Input a correct number.");  
        }
       while (n != 1) 
       {  
            if (n % 5 == 0) 
            {  
                n /= 5;  
            } 
            else if (n % 3 == 0) 
            {  
                n /= 3;  
            } 
            else if (n % 2 == 0) 
            {  
                n /= 2;  
            } 
            else
            {  
                printf("It is not an ugly number.\n"); 
                x = 1;  
                break;  
            }  
        } 
                if (x==0)
                { 
                printf("It is an ugly number.\n");
                }
}


c1. << Previous Next >> c3.

Copyright © All rights reserved | This template is made with by Colorlib