zoukankan      html  css  js  c++  java
  • 经典c程序 (0001)--取一个三位整数各位的数字

     1     /******************************************************************************************************************************* 
     2     * Function        : test 
     3     * Create Date  : 2014/03/12 
     4     * Author            : NTSK13 
     5     * Email             : beijiwei@qq.com 
     6     * Copyright       : 欢迎大家和我一起交流学习,转载请保持源文件的完整性。 
     7                                  任何单位和个人不经本人允许不得用于商业用途 
     8                                  转载请注明 转自 http://blog.csdn.net/beijiwei 
     9     * Version          : V0.1   
    10     * date                : 2014/03/12   
    11     * history            : V0.1    
    12     *****************************************************************************************************************************  
    13     经典c程序 (0001)  
    14      
    15      
    16     题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 
    17     1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 
    18           掉不满足条件的排列。  
    19      
    20     ****************************************************************************************************************************/  
    21     #include<stdio.h>  
    22     #define MY_FUNC  1  
    23     #if MY_FUNC  
    24     int main()  
    25     {  
    26         int i=0,j=0,z=0;  
    27         printf("The total number is %d 
    ",4*3*2);  
    28         printf("They are:
    ");  
    29        
    30        for(i=1;i<5;i++)//百位数字  
    31        for(j=1;j<5;j++)//十位数字  
    32        for(z=1;z<5;z++)//个位数字  
    33        {  
    34         if(i==j || i==z || j==z)  
    35         continue;  
    36         printf("The number is %d 
    ",i*100+j*10+z);  
    37        }  
    38        return 0;  
    39     }  
    40     // refer answer  
    41     #else  
    42     int main()  
    43     {  
    44         int i,j,k;  
    45         printf("
    ");  
    46           
    47         for(i=1;i<5;i++)  
    48         for(j=1;j<5;j++)  
    49         for(k=1;k<5;k++)  
    50         {  
    51             if (i!=k&&i!=j&&j!=k)/*确保i、j、k三位互不相同*/  
    52             printf("%d,%d,%d
    ",i,j,k);  
    53         }  
    54     }  
    55     #endif  
  • 相关阅读:
    0593. Valid Square (M)
    0832. Flipping an Image (E)
    1026. Maximum Difference Between Node and Ancestor (M)
    0563. Binary Tree Tilt (E)
    0445. Add Two Numbers II (M)
    1283. Find the Smallest Divisor Given a Threshold (M)
    C Primer Plus note9
    C Primer Plus note8
    C Primer Plus note7
    C Primer Plus note6
  • 原文地址:https://www.cnblogs.com/ntsk13/p/3732213.html
Copyright © 2011-2022 走看看