C language----Loop Branch iOS Learning-----Fine-grained knowledge points summary

Source: Internet
Author: User
Tags arithmetic operators case statement

#import <Foundation/Foundation.h>//#import是OC种的导入头文件或者是系统框架的指令

Defines a season enumeration type
Enum Season {
Spring = 1,//value starts from 0, followed by 1
Summer,
Autumn,
Winter
}; // ";" Cannot omit
int main (int argc, const char * argv[]) {

/*
In the C language, there is no bool type in c89, and the bool type is added to the C99, which is a "non-0 is true" data type, True and False
In OC, there is a bool data type, "not true or false", the value is only Yes and no,yes represents the result of the expression is true, no represents the result of the expression is false
printf ("%lu\n", sizeof (BOOL)); sizeof () is an operator that can find a data type or the number of bytes that a variable takes up

BOOL isyes = YES; Define a variable of type bool, assigning the initial value to Yes
BOOL isNo = NO;
printf ("%d---%d\n", isyes, IsNo);
*/
#pragma mark-relational operators:>, >=, <, <=, = =,! =, you have now learned three operators, their precedence: arithmetic operators > Relational operators > Assignment operators
BOOL bigger = 7! = 5;
printf ("%d\n", bigger);

int NUM1 = (4 + 5) > 2;
printf ("NUM1 =%d\n", NUM1);
#pragma mark-Logical expression: Logic and (&&), logic or (| |), logical non (!)
int NUM1 = 1;
int num2 = 0;
BOOL Isand = Num1 && num2++; Short circuit phenomenon: expression 1 && expression 2, when the result of expression 1 is false, the subsequent expression 2 will not be executed, the result of the entire expression is false
printf ("Isand =%d\n", num2);

BOOL Ishuo = NUM1 | | num2++; Logical or short-circuit phenomenon: expression 1 | | Expression 2, if the result of expression 1 is true, then expression 2 is no longer executed, the result of the entire expression is true
printf ("Ishuo =%d, num2 =%d\n", Ishuo, num2);
printf ("---%d\n",!ishuo);

#pragma mark-if statements

printf ("Please enter CET-4 score: \ n");
int score = 0;
scanf ("%d", &score); Use score to receive the results we have entered.
GetChar (); Remove line breaks from keyboard buffers
If (score >= 425) {
printf ("Congratulations, Grades!\n");
}
printf ("If statement executed \ n");

#pragma mark-conditional operator

Maximum number of outputs in two digits
int NUM1 = n, num2 = 20;
int maxnum = 0; To receive the maximum value
if (Num1 > Num2) {
Maxnum = NUM1;
} else {
Maxnum = num2;
//    }
Maxnum = NUM1 > num2? num1:num2; Conditional operator "conditional expression?" Expression 1: Expression 2 "
printf ("Maximum value:%d\n", maxnum);

#pragma mark-switch-case

Enter numbers 1, 2, 3, 4, respectively, to output the English words of spring and autumn.
printf ("Please enter a number between 1~4: \ n");
int season = 0;
scanf ("%d", &season);
Switch (season) {
Case Spring:
{
int num = 10; If you define a variable in a case statement, you must add ""
printf ("spring\n"); If there is no break in the case statement, then all cases statements that follow the condition are executed
Break
}
Case Winter:
{
printf ("winter\n");
Break
}
Case Summer:
{
printf ("summer\n");
Break
}
Case Autumn:
{
printf ("autumn\n");
Break
}
Default
{
printf ("Your input is incorrect, please re-enter it as prompted. \ n");
Break
}
}
Enum Season aspring = Spring; Defines a variable of an enumeration type and gives the initial value
return 0;
}
#pragma mark-while cycle

Always output large water meter
while (YES) {///1, loop condition
printf ("Flood watch \ n"); 2. Circulation body
}
Output 10 series Large water meter
int count = 0; Defines an integer variable int that is used to record the number of times the flood table is output
while (Count < 10) {
printf ("Flood watch \ n");
count++; The number of times the output is recorded, each time the loop body is executed, and the value of the variable is 1
}
Multiples of 7 between output 1~100
int num = 1;
while (num <= 100) {
if (num% 7 = = 0) {
printf ("%d\n", num);
}
num++; Change in cyclic increments
}
The number of bits between output 1~100 is 7
int num = 1; 1. Initialization of cyclic variables
while (num <= 100) {//2, loop condition
3. Circulation body
if (num% 10 = = 7) {
printf ("%d is the number of bits 7 \ n", num);
}
num++; 4, the change of the cyclic increment
}
10-digit number 7 between output 1~100
int num = 1; 1. Initialization of cyclic variables
while (num <= 100) {//2, loop condition
3. Circulation body
if (NUM/10 = = 7) {
printf ("%d is 10 bits is 7 of the number \ n", num);
}
4, the change of the cyclic increment
num++;
}
#pragma mark-random number
Negative numbers in the computer is in the form of a complement of storage, complement is from the anti-code plus 1 to the anti-code is from the original code by the position of the reverse.
int num =-1;
printf ("num =%lu\n", num);
Randomly generates a number
printf ("Randomnumber =%u", arc4random ());
Randomly generates a random number between [0, 30]
int num = arc4random ()% 31;
printf ("num =%d\n", num);

Randomly generates a random number between [10, 30]
int randomnum = Arc4random ()% (30-10 + 1) + 10;
printf ("Randomnum =%d\n", randomnum);

#pragma mark-break, end this loop, continue, end this cycle
int num = 0;
while (Num < 5) {
if (num = = 3) {
Break End this layer loop
num++;
Continue End of the cycle, continue to determine the conditions
}
printf ("%d\n", num);
num++;
}
#pragma mark-do-while cycle, whether the loop condition is satisfied, first executes a loop body, that is, the loop body is executed at least once
int num = 1;

do {
printf ("You hit me \ n");
} while (num > 1);

#pragma mark-for cycle

Print multiples of 7 between 1~100
for (int i = 1; i < 101; i++) {
if (i% 7 = = 0) {
printf ("%d is a multiple of 7 \ n", i);
}
}
#pragma mark-loop nesting

Print 99 multiplication table
for (int i = 0; i < 9; i++) {
for (int j = 0; J < i + 1; j + +) {
printf ("%dx%d =%d\t", j + 1, i + 1, (j + 1) * (i + 1)); "\ T" aligns the output
}
printf ("\ n");
}

C language----Loop Branch iOS Learning-----Fine-grained knowledge points summary

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.