C语言练习5

//
//  main.c
//  exercise5
//
//  Created by Vision on 14-9-4.
//

#include <stdio.h>
#include "Myfunction.h"
#include "Operator.h"
int main(int argc, const char * argv[])
{
//    int a, b, c;
//    scanf("%d.%d.%d", &a, &b, &c);
//    printf("%d\n",days(a, b, c));
//    int num;
//    scanf("%d", &num);
//    printf("%d\n",weishu(num));
//    revers(num);

//    unsigned year, mouth, day;
//    scanf("%u-%u-%u", &year, &mouth, &day);
//    unsigned d = days(year, mouth, day);
//    if (day > 0) {
//        printf("%u\n",d);
//    } else {
//        printf("error");
//    }
    
    
//    int x, y;
//    scanf("%d %d", &x, &y);
//    printf("%d",maxValue(x, y));
//    printf("%d",minValue(x, y));
//    printf("%d",sumValue(x, y));
//    printf("%d",avgValue(x, y));
    
    int x = 0;
    scanf("%d", &x);
    printInt(x);
    return 0;
}
</pre><pre name="code" class="objc">
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(29, 148, 33);"></p><pre name="code" class="objc">//
//  Myfunction.h
//  exercise5
//
//  Created by Vision on 14-9-4.
//

#ifndef exercise6_Myfunction_h
#define exercise6_Myfunction_h

#include <stdbool.h>

///判断是否闰年
unsigned int runnian(unsigned int);

///检查日期正确性
bool checkDate(unsigned int year, unsigned int mouth,unsigned int day);

///输入年月日,输出总天数
unsigned int days(unsigned int ,unsigned int ,unsigned int);

///输入数字,输出位数
unsigned int weishu(unsigned int);

///逆序输出数字
void revers(unsigned int);

///产生一个逆序整型数字(面试题)
unsigned int reversInt(unsigned int n);

///正序按位输出整型数字
void printInt(unsigned int n);

int pingfang(int ,int);
#endif
</pre><pre name="code" class="objc">
</pre><pre name="code" class="objc">//
//  Myfunction.c
//  exercise5
//
//  Created by Vision on 14-9-4.
//

#include <stdio.h>
#include "Myfunction.h"
#include <math.h>

unsigned int runnian(unsigned int n)
{
    return ((n % 4 == 0 && n % 100 !=0) || (n % 400 == 0));
}

bool checkDate(unsigned int year, unsigned int mouth,unsigned int day)
{
    bool result = true;
    unsigned days = 0;
    switch (mouth) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            days = 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            days = 30;
        break;
        case 2:
            days = 28 + runnian(year);
            break;
            
        default:
            break;
    }
    if (0 == day || day > days || 0 == day) {
        result = false;
    }
    return result;
}

unsigned int days(unsigned int x, unsigned int y, unsigned int z)
{
    int day = 0;
    if (!checkDate(x, y, z)) {
        return day;
    }
    switch (y - 1) {
        case 11:
            day += 30;
        case 10:
            day += 31;
        case 9:
            day += 30;
        case 8:
            day += 31;
        case 7:
            day += 31;
        case 6:
            day += 30;
        case 5:
            day += 31;
        case 4:
            day += 30;
        case 3:
            day += 31;
        case 2:
            day += 28 + runnian(y);
        case 1:
            day += 31;
    }
    day += z;
    return day;
}
unsigned int weishu(unsigned int n)
{
    unsigned int i = 0;
    while (n > 0) {
        i++;
        n = n / 10;

    }
    return i;
}
void revers(unsigned int n)
{
    unsigned int yushu = 0;
    while (n > 0) {
        yushu = n % 10;
        printf("%d",yushu);
        n = n / 10;
    }
}

unsigned int reversInt(unsigned int n)
{
    int m = 0, x = 0;
    while (n) {
        m = n % 10;
        x = x * 10 + m;
        n /= 10;
    }
    return x;
}
int pingfang(int x,int i)
{
    for (int j = i; j > 0; j-- ) {
        x *= 10;
    }
    return x;
}
void printInt(unsigned int n)
{

    int i =  weishu(n);
    while (i > 0) {
        printf("%d\n",  n % );
        i--;
    }
}




//
//  Operator.h
//  exercise6
//
//  Created by Vision on 14-9-4.
//

#ifndef exercise6_Operator_h
#define exercise6_Operator_h

int maxValue(int, int);
int minValue(int, int);
int sumValue(int, int);
int avgValue(int, int);


#endif



//
//  Operator.c
//  exercise5
//
//  Created by Vision on 14-9-4.
//

#include <stdio.h>

#include "Operator.h"

int maxValue(int a, int b)
{
    return (a > b ? a : b);
}

int minValue(int a, int b)
{
    return (a < b ? a : b);
}

int sumValue(int a, int b)
{
    return (a + b);
}

int avgValue(int a, int b)
{
    return ((a + b) / 2);
}



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值