码迷,mamicode.com
首页 > 其他好文 > 详细

戴维营第三天上课总结

时间:2014-09-17 21:42:02      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   数据   2014   

今天轮到大茶给我们讲课, 给我们更加详细的讲解各个数据类型, 以及其他关键字, 并且给我们演示怎么用代码编写一个计算器, 还有怎么算闰年, 左移等等知识点, 其中的代码有

#include <stdio.h>

int main(int argc, const char * argv[]) {
    int16_t y = 14, m = 9, d =17;
    int16_t data = 0;


//y<<9                   //  0000  0000 0000 1110 
           // 0001 1100 0000 0000
(在一年之内, 存储只到2^7, 所以前面9个0就是没意义的, 就缩写成第二个状态)
//(m<<12)>>7
    //  0000 0001 0010 0000
//(d<<11)>>11// 0000 0000 0001 0001

    
    data = (y<<9)|((m<<12)>>7)|((d<<11)>>11);
    
    printf("%02x\n", data);
    
    return 0;
}
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int year;
    
    printf("请输入年份: ");
    scanf("%d", &year);
    
    if((0 == year%4)||((0 == year%400)&&(0 != year%100)))
    {
        printf("是闰年\n");
    }
    else
        printf("不是闰年\n");

    return 0;
}
//
//  ViewController.m
//  demo2
//
//  Created by apple on 14-9-17.
//  Copyright (c) 2014年 apple. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    NSString *op1, *op2;
    char op;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    op1 = @"";
    op2 = @"";
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)button1clicked:(id)sender {
    NSLog(@"1 clicked");
    if (op != + && op != -
        && op != * && op != /) {
        //1231
        op1 = [NSString stringWithFormat:@"%@%d", op1,1];
    }else
    {
        op2 = [NSString stringWithFormat:@"%@%d", op2,1];
    }
}
- (IBAction)button2clicked:(id)sender {
    NSLog(@"2 clicked");
    if (op != + && op != -
        && op != * && op != /) {
        //1231
        op1 = [NSString stringWithFormat:@"%@%d", op1,1];
    }else
    {
        op2 = [NSString stringWithFormat:@"%@%d", op2,1];
    }
}
- (IBAction)button3clicked:(id)sender {
    NSLog(@"3 clicked");
    if (op != + && op != -
        && op != * && op != /) {
        //1231
        op1 = [NSString stringWithFormat:@"%@%d", op1,1];
    }else
    {
        op2 = [NSString stringWithFormat:@"%@%d", op2,1];
    }

}


- (IBAction)add:(id)sender {
    op = +;
}
- (IBAction)jieguo:(id)sender {
    if (op == +) {
        //NSString转int整形数值
        int a1 = [op1 intValue];
        int a2 = [op2 intValue];
        int sum = a1 + a2;
        NSLog(@"%d", sum);
        NSString *result = [NSString stringWithFormat:@"%d", sum];
        self.jieguo.text = result;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

由于题目和思路累积的少, 所以应付这些题非常的吃力, 不过还好还有其他同学可以一起交流, 给我详细的讲解其中的原由, 这让我茅舍顿开, 希望以后大家继续保持这种学习状态, 一起讨论一起交流~~~

戴维营第三天上课总结

标签:style   blog   color   io   os   ar   for   数据   2014   

原文地址:http://www.cnblogs.com/iOSCain/p/3978013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!