Programmer account notes (4)

xiaoxiao2021-03-06  93

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, it is the algorithm. The original sort rules are inserted into an array.

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 8main () {Int a [n] = {20, 30, 40, 50, 60, 70, 80}; int N, i; for (i = n-1; 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. But more importantly, it is: don't let people feel as dizziness as the source program, I don't know what this is something. Because I also finished reading this program, I saw the model model, so I recommend everyone to learn this method. Speaking of sorting, the teacher taught us a new sort method, 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 A [J 1] {exchange}; or more is the bubbling method INT N = 6, I, J; for (i = 0; i i; J -) IF (a [J]

This is sinking.

We are basically practicing this sort today. It's time to get out of school, but the teacher still grasped the time, it is really not wasteful, and also dragged half a hour.唉 ~! Sometimes I feel that others are good, it is really bad. But what said, he is our teacher. Then he dragged us half a minute is to finish the conditional statement in the C language, but it really has learned something.

There are several forms of Conditional statements in the C language, with conditional operators?: The operator is operator. Why is this flexible, because his parameters are expressions, the c language is the most flexible, then can it be flexible! A source program is given here:

INT A = 5, B = 10, c = 8;

IF (a> b)

IF (a> c) Printf ("a");

ELSE IF (B> C) Printf ("b");

Else Printf ("c");

Whether such a source makes 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 program is also very short, let me say the answer is good, the answer is not to output B, the reason is very simple to see, who? Who? Who is messing here, will the answer be output B, stupid! So write your hard work, you can't get home, let's make 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! It also shows a situation here, so we have to accompany the format of the code, if there is a good program, there is a good program. And I understand today, I want to see the following IF statement:

IF IF

Else Else IF

IF Else IF

Else Else IF

IF

Else

I still thought that these two are different, the impression in QB is two non-IF statements. But today I will understand it, everyone should know, maybe I am stupid. In the C language, SWTICH is also different from other senior languages. Do you have found? Now look at the fourth day.

In this figure, the statement is clearly illustrated by this statement, and the condition is used for constants, so the teacher said that he listened to him and didn't like to use this SWTICH statement. If you understand this conditional operator? : It is really convenient, this is also unlimited, not much here, let yourself feel slowly.


New Post(0)