C Study notes and after-school assignments

Source: Internet
Author: User
Tags array definition delete key

One

1. Introduction to Mac System-basic functions

1.1commad+ Space Toggle Input Method

1.2 System comes with screenshot function (command+shift+3, command+shift+4)

1.3 All settings can be adjusted by "preferences" (shortcut is command+,)

1.4ctrl+ key to switch desktop, CTRL + Add desktop on the key

1.5 command+shift+ Delete key empty trash

1.6 Application Switching Command+tab

1.7 Exiting the current app Command+q

1.8 Close the current window command+w

2. Xcode

Two

1. C Language Foundation

1.1 Conversion method: Weighted sum, and even remove the residual (10 conversion to other methods of the input system)

1.2 binary with B, octal is denoted by 0, decimal is denoted by H, hexadecimal is represented by 0X

1.3 Comments (single-line and multiline comments)

1.4. Basic data types: char, int, short, long, float, double

1.5, sizeof use method, sizeof output value using%lu;

1.6, constant: The amount of non-change during program operation.

1.7, float type maximum can represent 6 decimal digits precision, and double type maximum can represent 15 decimal digits precision. A double occupies 4 bytes in a 32-bit system and 8 bytes in a 64-bit system. But the double type, by default, outputs 6 digits after the decimal point, and we usually reduce its length after the decimal point. You can use the form "%M.NLF", where both M and n are positive integers. M represents the output of the floating-point data for the M-bit, if the actual length is not equal to M, then the actual length of the output, n represents the number of decimal digits of the output. So, M can actually do without tube, directly with 0 instead of or not write can!

1.8. Remember the following formatting string:

Remember the following formatting string:

Code format:

Percent of a '% ' sign

%c character

%d signed integers

%i signed integer

%e scientific notation, using lowercase "e"

%E scientific notation, using uppercase "E"

%f floating Point

%g use the shorter one in%e or%f

%G use the shorter one in%e or%f

%o Octal

%s A string of characters

%u unsigned integer

%x unsigned hexadecimal number, in lowercase letters

%x unsigned hexadecimal number, in uppercase letters

%p A pointer

The%n parameter should be a pointer to an integer

Point to the position where the number of characters is placed

1.9. command+ Backslash Add Breakpoint

2.0, C in a total of 32 keywords

2.1. Expressions: Valid and reasonable combinations of constants, variables and operators, and expressions have values;

Three

1.1, type bool: not 0 is true. Only true and false two states. (in standard C language there is no bool type, starting from the C99 version to add bool type) in OC Use Yes to express true, use No for false; Other languages, generally use true to denote true, false is used;

1.2. Relational operators

1.3. Logical operators

1.4, Operator precedence: arithmetic operators > Relational operators > Logical operators > Assignment operators

1.5. Logical operators

1.6, C in three kinds of structure: sequential structure, branch structure, circular structure

1.7, the variables and case values in the switch statement must be shaped, not other types;

1.8, the data type is divided into the basic data type and the special type, the special type includes the bool type and the construction type, the construction type also includes the enumeration, the array and so on;

1.9, pay attention to the enumeration type of learning;

2.0, the use of TypeDef method.

Four

1, while loop, Do-while Loop, for loop;

2, the use of random number Arc4random () method, Arc4random (); The type of the output random number is the unsigned int type, the data range is 0--2^31-1;

3. When the maximum value is obtained, the initial value defined by Max cannot be larger than any random number, and the initial value defined by min cannot be smaller than any random number when the minimum value is obtained;

4, circulating structure pharmacy: Cycle initial value-decide where the cycle starts;

Loop condition-Determines whether the loop continues (when it ends)

Loop body-Decide what I'm going to do (content)

Cyclic increment-function of counting (to prevent dead loops)

5, C/oc in the N-order of M can use the function pow (m,n);

6, the variable name rule: variable names can only have numbers, letters, underscores, and can not be the beginning of the number; cannot be the same name as the System key, the same scope variable names can not be duplicate; variable names are known;

7, array int a[10]; its data type is int [10], and the variable name is a;

8, character array definition way: char string[10]={' A ', ' B ', ' C ', ' d ', ' e '};

Char string[10]= "ABCDE"; there is an invisible \ n character;

Char *string= "ABCDE"; there is an invisible \ n character;

9. An array of characters that have the ' \ S ' End identifier is also known as a string.

The system-supplied string handler functions include:

Strlen (); Calculates the string (valid) length, excluding the length of '% ', for example: Char string[]= "ios", string length is 3 characters, and memory allocation space is 4 characters.            

strcpy (); string copy, example: strcpy (b, a);

Strcat (); string concatenation

STRM p (); string comparison

What is the space for a string? At least to be more than a string, length, 1, because the string ends with a ' + ' table. The string handler provided by the system determines whether the string ends in terms of '% '.

10. The char type can print its ASCII code using%d, or it can print its value using%c, where char defaults to signed char, with a value range of 128 to 127, or unsigned char, which can range from 0 to 256;

Example: int main (int argc, char *argv[])

{

unsigned char str[10], I;

for (i = 0; i < 255; i++)//256 to 255

printf ("%d\n", I);

printf ("%d", I);

printf ("%d\n", I);

printf ("addbhakdhkj");

Str[i] = i;

printf ("%d\n", I);

printf ("%c\n", I);

return 0;

}

/*13, (* * *) simulates n individual participation in the election process, and output election results: Assuming that there are four candidates, respectively, a, B, C, D, the election of a candidate, the direct input of their number (number is randomly generated by the computer),

If the input is not a, B, C, D is considered invalid, after the end of the election, the number of votes from high to low output candidate number and the number of votes obtained.

* * (Fourth class Assignment), pay attention to the implementation and sequencing of the addition (******* the name and number of votes bundled *********) important, important

Using the random number + array implementation

int main ()

{

int people_num;

printf ("Number of people entering the crowd:");

scanf ("%d", &people_num); Mass number input

int candidate = 0; Candidate number

int tickets[4]={0,0,0,0}; Candidate votes A[0], number of votes on behalf of a

Char people[4]={' A ', ' B ', ' C ', ' D '};

printf ("The resulting random ticket is:");

for (int i = 0; i < people_num; i++)

{

Candidate=arc4random ()% (4-0+1);//generated with the ticket, 0 on behalf of the A,1 representative b,2 on behalf of c,3 representative d,4

printf ("%d\t", candidate);

if (Candidate > 3) {

Continue

}else{

tickets[candidate]++;

}

}

for (int i = 0; I <4-1; i++) {

for (int j = 0; j< 4-i-1; j + +) {

if (Tickets[j] < tickets[j+1]) {

int temp = 0;

temp = Tickets[j];

TICKETS[J] = tickets[j+1];

TICKETS[J+1] = temp;

Char temp2 = ' 0 ';

Temp2 = People[j];

PEOPLE[J] = people[j+1];

PEOPLE[J+1] = Temp2;

}

}

}

printf ("\ n");

for (int i = 0; i< 4; i++) {

printf ("%c%d\n", People[i], tickets[i]);

}

return 0;

}

Job: Note that some of the procedures in the job through the array are particularly convenient, such as the printing of a diamond can be made by defining two arrays, one holding a space, the other holding the *, which makes it easy to implement the printing process.

C Study notes and after-school assignments

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.