C 练习实例1
C 语言教程
· 2019-02-21 12:13:55
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。
实例
#include<stdio.h>
int main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++) { // 以下为三重循环
for(j=1;j<5;j++) {
for (k=1;k<5;k++) { // 确保i、j、k三位互不相同
if (i!=k&&i!=j&&j!=k) {
printf("%d,%d,%d\n",i,j,k);
}
}
}
}
}
以上实例输出结果为:
1,2,3 1,2,4 1,3,2 1,3,4 1,4,2 1,4,3 2,1,3 2,1,4 2,3,1 2,3,4 2,4,1 2,4,3 3,1,2 3,1,4 3,2,1 3,2,4 3,4,1 3,4,2 4,1,2 4,1,3 4,2,1 4,2,3 4,3,1 4,3,2
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
An Introduction to the Analysis of Algorithms
Robert Sedgewick、Philippe Flajolet / Addison-Wesley Professional / 1995-12-10 / CAD 67.99
This book is a thorough overview of the primary techniques and models used in the mathematical analysis of algorithms. The first half of the book draws upon classical mathematical material from discre......一起来看看 《An Introduction to the Analysis of Algorithms》 这本书的介绍吧!