//
// main.m
// C3_循环结构
//
// Created by YIem on 15/11/12.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

/* // 限时代码 4min

char a = 0;
scanf("%c", &a);
if (a > '0' && a < '9') {
    printf("数字\n");
}   else if (a > 'a' && a < 'z'){
    printf("小写字母\n");
}   else if (a >'A' && a < 'Z'){
    printf("大写字母\n");
    
}   else{
    printf("其他\n");
}
*/

/****** 程序的三种结构******/
//  顺序 分支 循环


// 循环
    //满足条件时 重复做某事
    // 循环条件 下重复执行  一段代码


/****** for 循环 ******/
// 循环增量初始化    条件        增量变化

// for (int i = 0; i < 5; i++) {
// printf("Yiem n");
// // system("say YIem");// 系统函数 发出声音
// }
// // 死循环
// for (; YES; ) {
// printf("死循环n");
// }


    //练习: 正序打印1-5的数
    //

// for (int i = 1; i <= 5; i++) {
// printf("%dn", i);
// }
// for (int i = 5; i >= 1; i--) {
// printf("%dn", i);
// }

// // 练习 打印1-100之间的偶数
// for (int i = 1; i <= 100;i++) {
// //判断偶数
// if (i % 2 ==0){
// printf("%dn", i);
// }
//
// }

// 练习  1用for打印出1-100之间7的倍数
//      2用for打印1-100个位为7的数
//      3用for打印出1-100之间十位为7的数
//      4用for打印出1-100之间不是7的倍数并且不包含7的数

// for (int i = 1; i <= 100; i++) {
// if (i % 7 ==0) {
// printf("%dn", i);
// }
//
// }
// for (int i = 1; i <= 100; i++) {
// if (i % 10 == 7) {
// printf("%dn", i);
// }
// }
// for (int i = 1; i <= 100; i++) {
// if (i / 10 ==7) {
// printf("%dn", i);
// }
// }

// 第一种

// for (int i = 1; i <= 100; i++) {
// if (i % 7 != 0 && i % 10 != 7 && i / 10 !=7) {
// printf("%dn", i);
// }
//
// }

//第二种

// for (int i = 1; i <= 100; i++) {
// if (! (i % 7 == 0 || i / 10 == 7 || i % 10 ==7)) {
// printf("%dn", i);
// }
//
// }
/*
// 敲7 游戏

for (int i = 1; i <= 100; i++) {
    if (60 == i) {
        printf("Game Over\n");
        break;// 打断/终止 本层循环
    }
    if (i % 7 ==0 || i / 10 ==7 || i % 10 == 7) {
        printf("啪\n");
        continue;// 继续循环 跳过后续的代码
    }
    printf("%d\n",i);
    
}


*/

/ 随机数**/
// printf("%dn",arc4random() % 11);

// 范围随机数的公式  最大值  最小值     最小值
// arc4random() % (max - min + 1) + min

// printf("%dn", arc4random() % (98 - 46 + 1) + 46);


// 练习 用for打印10个随机数(范围10-30),求最大值和最小值

//  第一种
/*
for (int i = 0; i < 10 ; i++) {
    printf("%d\n", arc4random() % (30 - 10 + 1) + 10);
}
 */
//  第二种
/*
int max = 0, min = 30;// 解决方案1
for (int i = 0; i < 10 ; i++) {
   int a =  arc4random() % (30 - 10 + 1) + 10;
    printf("%d ", a);
    max = max > a ? max : a;
    // 第一次进入循环时 直接赋值
    if (0 == i){
        min = a;// 解决方案2
    }
    min = min < a ? min : a;
 */
    /* 第二种 最大值最小值 解决方案
    if (max < a){//最大值
        max = a;
    }
    if (0 == i || min > a){//最小值
        min = a;
    }
     */

// }

// 最小值 有两种解决方案

// printf("n");
// printf("max = %dn", max);
// printf("min = %dn", min);
//

/ 循环嵌套**/

// 外层循环控制 行数

// for (int j = 0; j < 3; j++){
// //内层循环控制 一行中的内容长度
// // 打印5个*
// for (int i = 0; i < 5; i++){
// printf(" * ");
// }
// // 回车
// printf("n");
// }

/*
int w = 0 , l = 0;// 自定义 打印几行
printf("请输入\n");
scanf("%d", &w );
printf("请输入\n");
scanf("%d", &l );

for (int i = 0; i < w; i++){
    for (int j = 0; j < l; j++) {
        printf("*");
    }
    printf("\n");
}
 */

/*

for (int i = 0; i < 4; i++){
    
            // 打印空心
    if (i != 0 && i != 4 - 1) {// 是否是第二行和第三行是第二行或者是第三行的时候进行打印*
        //
        printf("*");
        // 打印空格
        for (int j = 0; j < 6 - 2; j++) {
            printf(" ");
        }
        printf("*");
        printf("\n");
        continue;
    }
            for (int j = 0; j < 6; j++){
                printf("*");
            }
            // 回车
            printf("\n");
        }

*/
/*

// 练习: 打印9*9乘法口诀
for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= i; j++) {
        printf(" [ %d * %d = %d ] ", j, i, j * i);
    }
    printf("\n");
}

*/

if 0

// 练习: 000-999
// 百位
for (int i = 0; i < 10; i++) {
    // 十位
    for (int j = 0; j < 10; j++) {
       // 个位
        for (int k = 0; k < 10; k++) {
            printf("%d %d %d\n", i, j, k);
        }
    }
}

endif

if 0

/****** while******/
int i = 1;
while (i <= 100) {
    printf("%d\n", i);
    // while 中一定不要忘记写循环变量的增加
    i++;
}

// for 模拟while
int j = 1;
for (; j <= 100;) {
    printf("%d\n", j);
    j++;
}

endif

if 0

// 练习 : 10亿 每天花一半  能花多少天

int money = 1000000000, days = 0;
//当有钱时 循环继续
while (money) {
    //每天 花一半
    money /= 2;
    days++;
}
printf("%d\n", days);

endif

/ do...while 循环**/
/* int i = 1;

do {
    printf("%d\n", i);
    i++;
} while (i <= 100);

//while死循环
//  1/YES
while (1) {
    
}
//for死循环
for (; 1; ){
    
}

*/

if 0 // int的最大值 + -21亿之间

//  练习" 输入一个整数 求这个整数的位数
int num = 0, b = 0;
printf("输入:\n");
scanf("%d", &num);

while (num) {
    num /= 10;
  
    b++;
}
printf("%d\n", b);

endif


return 0;

}