C Language Learning 1

Source: Internet
Author: User
"Program 1"
Title: There are 1, 2, 3, 4 numbers, can make up how many different and no repetition of the number of three digits? How much are they?
1. Program Analysis: Can be filled in the hundred, 10 digits, digit digits are 1, 2, 3, 4. make all the permutations and then remove the permutations that do not meet the criteria .

2. Program Source code:

#include "stdio.h" #include "conio.h" main () {  int i,j,k;  printf ("\ n");  for (i=1;i<5;i++)/* The following is a triple loop */For    (j=1;j<5;j++) for      (k=1;k<5;k++)      {        if (i!=k&&i!=j &&J!=K)/* Make sure I, J, K three bits are different */        printf ("%d,%d,%d\n", i,j,k);      }  Getch ();}

I think the most used idea in this program is to first combine all three digits and remove the number of unsatisfied conditions.

In fact, my first idea is: put a number on the top, then the second place with the first different number, the third place with the 12th number of different numbers, this idea is actually feasible, but the implementation of the program, you will find a lot more than the above procedure. So the idea of people and the operation of the machine is very different, want to write a good C language program, it is important to learn C program thinking mode.

All say the algorithm is very difficult, all think the algorithm is very tall, but I think this simple small program is an algorithm, because it solves a problem, can solve the problem of the program can be considered algorithm


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C Language Learning 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.