Programmer exam remedial note - the fourth day

zhaozj2021-02-16  59

I really don't know why, all of my words have changed, but it is the macro poison of Word. But why is it infected? This is really strange, I have not used macro. Forget it, there is no time to pay now, I have to hurry to write this tutorial diary.

Today's curriculum is finally focusing, it is the algorithm, because only start, first start from an easy sorting algorithm, copy a topic, let us do, as follows:

There is already a sorted array, and you will enter a number in the original sort rules.

I saw this topic, I feel that I am more sure, I have written it out, but who knows that my program has a dead place, just gave the teacher to see it, but I finished my mistake. It's really bad, since all wrong, write down the answer I do, but let everyone compare.

#define n 8

Main ()

{

INT A [N];

INT I, J, T, S;

For (i = 1; i <= 7; i )

a [i-1] = i * 10;

For (i = 0; i <7; I -)

IF (a [i]

{s = a [i]; a [i] = a [i 1]; A [i 1] = s;}

For (i = 0; i <7; i )

Printf ("% D, A [i]);

}

It seems really right, there is no mistake, maybe it is not careful. The teacher is that this kind of skill can be seen, let me slowly come to my mistake, in fact, it is wrong to finally don't assign an element, because there is no initial pass value, the number of random builds may be large, or may be very Less, but if you just smaller than the plug, it is no longer correct. Ok, I said my mistake, let us see a correct program.

#define n 8

Main ()

{

INT A [n] = {20, 30, 40, 50, 60, 70, 80};

INT N, I;

For (i = 8; I> = 0; I -)

{

IF (n

Else Break;

}

a [i 1] = n;

}

Here is a better sorting algorithm. When you tell these sort, the teacher draws a picture, such as the fourth day.

This figure can be convenient to indicate the sorting situation at the time, and the sequence is clearer. However, more importantly, it is not to make people only look at the source program. I don't know what this is. Because I also finished reading this program, I saw the model model, so I recommend everyone to learn this method.

Speaking of sorting, we teach us a new way of sorting, which is the bubbling order. I remember that I have learned in QB before, but I listened to the teacher today that I have a hand drawing, I really become more clear. It is said that the bubble sorting method can also be called the left downstreaming method, because it is determined by the two loops of the procedure. If it is from the bottom to the top, it is Of course, it is bubble. On the contrary, it is sinking from the top. Obvious two programs:

INT n = 6, i, j;

For (i = N-1; I> 0; I -)

For (j = 0; j

IF (a [j]> a [j 1] {exchange};

The above is the bubbling method

INT N = 6, i, j; for (i = 0; i i; j--) IF (A [J] b) IF (a> c) Printf ("a"); ELSE IF (b> c) Printf ("b"); Else Printf ("C) "); Do you make you feel uncomfortable? This is another feature of the C language. Do you know the answer to this procedure? But it is not difficult, the procedure is also very short, let me Say the answer, the answer is not to output B, the reason is very simple to see, who? Who? Who is messing here, the answer will be output B, stupid! So you can't get home, The following allows the program int a = 5, b = 10, c = 8; if (a> b) IF (a> c) Printf ("a"); ELSE IF (B> c) Printf ("b") Else Printf ("c"); Is this clear? The answer is nothing, because the first IF statement is not established, there is a answer! Here is a situation, so we have to accompany Raise the format of the code, if there is a good program, there is a good program. I understand today, I want to see the following IF statement: if IFELSE ELSE IFE ELSE IFELSE ELSE IFELSE I originally thought these two The one is different, the impression in QB is two not the IF statement. But I will understand it today. Everyone should know, maybe I am stupid. Swtich is also other in C language. Different language, have you found it? Now look at the fourth day. The two bars know this statement clearly, and the condition is used constant, so the teacher said to he listen to himself. How do I like to use this SWTICH statement. If Do you understand this conditional operator? : It is really convenient, this is also unlimited, not much here, let yourself feel slowly.


New Post(0)