| 
 
| 有问题的地方希望能帮忙提出来,也希望可以帮到大家一点 复制代码#include <stdio.h>
void boyOrGirl(int year,int mouth,int day)
{   //一年有多少天
    int dayOfYear = 0;
    //年数差换算成天数
    int sumOfYear = 0;
    //月数差换算成天数
    int sumOfMouth = 0;
    //天数差
    int sumOfDay = 0;
    //定义数组存放闰年12个月,每月的天数
    int runYear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
    //定义数组存放一般年12个月,每月天数
    int norYear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    
    for (int x = 2006; x < year; x++) {
        //判断如果输入年份是2006,则将年数差换算成的天数差为0
        if (year == 2006) {
            sumOfYear = 0;
        }else{
            if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0) {
                dayOfYear = 366;
            }else{
                dayOfYear = 365;
            }
            sumOfYear += dayOfYear;
        }
    }
    for (int m = 1; m < mouth; m++) {
        //判断如果输入月份是1,则将月数差换算成的天数差为0
        if (mouth == 1) {
            sumOfMouth = 0;
        }else{
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                sumOfMouth += runYear[m-1];
            }else{
                sumOfMouth += norYear[m-1];
            }
        }
    }
    sumOfDay = day - 1;
    
    //定义一个变量存放两个时间差换算成的总天数
    int allDays = sumOfDay + sumOfMouth + sumOfYear;
    printf("%d",allDays);
    
    if (allDays % 6 == 0) {
        printf("小明结识了一个美女和一个帅哥\n");
    }else if(allDays % 3 == 0){
        printf("小明结识了一个美女\n");
    }else if(allDays % 2 == 0){
        printf("小明结识了一个帅哥\n");
    }else{
        printf("小明目测宅家里没出去- -\n");
    }
}
void date()
{
    int a = 0;
    int b = 0;
    int c = 0;
    //do while循环对输入内容进行限制以及格式提示
    do {
        printf("请输入时间2006年1月1日之后的任意一天,输入格式例如:2008,2,15\n");
        scanf("%d,%d,%d",&a,&b,&c);
    } while (a < 2006||b > 13||c > 31);
    boyOrGirl(a, b, c);
}
int main(int argc, const char * argv[]) {
    // insert code here...
    //调用函数
    date();
    
    return 0;
}
 
 
 | 
 |