080425

来源:互联网 发布:淘宝上有卖电棍的吗 编辑:程序博客网 时间:2024/04/29 15:58

编写一个程序,要求计算出生日到计算日的总天数
算法:
1)输入出生年year1、月month1、日date1和计算日年year2、月month2、日date2。
2)统计year1到year2-1的总天数:
   for (n=year1,days=0;n<year2;n++)
     if (n是闰年) days+=366
     else days+=365;
  3)计算出出生日和计算日是当年的第days1和days2。   
  4)总天数等于days+days2-days1

根据结果,判断体力、情绪和智力状态
     方法如下:
       体力状态:用总天数除以23,余数在0~11为体力高潮期,否则为体力低潮期。
       情绪状态:用总天数除以28,余数在0~14为情绪高潮期,否则为情绪低潮期。
       智力状态:用总天数除以33,余数在0~16为智力高潮期,否则为智力低潮期。
#include <stdio.h>

void main(){
    int year1,year2;
    int month1,month2;
    int date1,date2;
    int n,m;
    int days = 0;
    int days1 = 0;
    int days2 = 0;
    int all_days;
 

    printf("please input your brithday(for example:year month day):");
    scanf("%d%d%d",&year1,&month1,&date1);
    printf("please input today(for example:year month day):");
    scanf("%d%d%d",&year2,&month2,&date2);

    for(n = year1; n < year2; n++){
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days = days + 366;
        }
        else
            days = days + 365;
    }
    printf("the year1to year2 has %d days/n",days);

  
    switch(month1){
    case 1:
        days1=date1;
       
        printf("the day is %d days in the year1/n",days1);
        break;
    case 2:
        days1=date1+31;
       
        printf("the day is %d days in the year1/n",days1);break;
      
    case 3:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else {
            days1=date1+31+28;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 4:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else {
            days1=date1+31+28+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 5:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else{
            days1=date1+31+28+31+30;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 6:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else {
            days1=date1+31+28+31+30+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 7:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30+31+30;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else{
            days1=date1+31+28+31+30+31+30;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 8:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30+31+30+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else{
            days1=date1+31+28+31+30+31+30+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 9:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30+31+30+31+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else {
            days1=date1+31+28+31+30+31+30+31+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 10:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30+31+30+31+31+30;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else{
            days1=date1+31+28+31+30+31+30+31+31+30;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 11:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=date1+31+29+31+30+31+30+31+31+30+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else {
            days1=date1+31+28+31+30+31+30+31+31+30+31;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    case 12:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days1=366-31+date1;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
        else {
            days1=365-31+date1;
            printf("the day is %d days in the year1/n",days1);
            break;
        }
    default :
        printf("data error");
   
    }
    switch(month2){
    case 1:
        days2=date2;
       
        printf("the day is %d days in the year2/n",days2);
        break;
    case 2:
        days2=date2+31;
       
        printf("the day is %d days in the year2/n",days2);break;
      
    case 3:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29;
            printf("the day is %d days in the year2/n",days2);
            break;
        }
        else {
            days2=date2+31+28;
            printf("the day is %d days in the year2/n",days2);
            break;
        }
    case 4:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else {
            days2=date2+31+28+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    case 5:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else{
            days2=date2+31+28+31+30;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    case 6:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else {
            days2=date2+31+28+31+30+31;
            printf("the day is %d days in the year2/n",days2);
            break;
        }
    case 7:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30+31+30;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else{
            days2=date2+31+28+31+30+31+30;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    case 8:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30+31+30+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else{
            days2=date2+31+28+31+30+31+30+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    case 9:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30+31+30+31+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else {
            days2=date2+31+28+31+30+31+30+31+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    case 10:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30+31+30+31+31+30;
            printf("the day is %d days in the year2/n",days2);
            break;
        }
        else{
            days2=date2+31+28+31+30+31+30+31+31+30;
            printf("the day is %d days in the year2/n",days2);
            break;
        }
    case 11:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=date2+31+29+31+30+31+30+31+31+30+31;
            printf("the day is %d days in the year2/n",days2);
            break;
        }
        else {
            days2=date2+31+28+31+30+31+30+31+31+30+31;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    case 12:
        if((((n % 4) == 0)&&((n % 100) != 0)) || (n % 400) == 0){
            days2=366-31+date2;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
        else {
            days2=365-31+date2;
            printf("the day is %d days in the year2 /n",days2);
            break;
        }
    default :
        printf("data error/n");
   
    }
    all_days=days+days2-days1;
    printf("in all days is %d/n",all_days);
   

    if ((all_days/23)>=0&&(all_days/23)<=11){
        printf("sinew is climactic ! /n");
    }
    else
        printf("sinew is lower!/n");


    if ((all_days/28)>=0&&(all_days/28)<=41){
        printf("mood is climactic !/n ");
    }
    else
        printf("mood is lower!/n");
   

    if ((all_days/33)>=0&&(all_days/33)<=16){
        printf("wit is climactic ! /n");
    }
    else
        printf("wit is lower!/n");
}

 

 

 1. 编写一个程序求c =a+ | b | , 输出c 的值, 其中a和b为整数
     ( 绝对值函数请查函数库中的math.h 文件)
(1)解
#include <stdio.h>

int main(){
    float a,b;
 
    float sum;
    scanf("%f%f",&a,&b);
    if(b < 0){
        b = -b;
    }
    sum = a + b;
    printf("%f/n",sum);
}
(2)解
#include <stdio.h>
#include <math.h>
void main(){
    float a,b;
    float c;
    float sum;

    scanf("%f%f",&a,&b);
    c=abs(b);
    sum=a+c;
    printf("sum is %f/n",sum);

}
 2. 写出下面程序的输出结果
  #include <stdio.h>
  void main( )
  {  int x , y , z ;
     x = -3+4*5-6 ;     printf("x=%d/n", x);//x=11
     y = -3*4%-6/5 ;  printf("y=%d/n", y);//y=0
     z = (7+6)%5/2 ;    printf("z=%d/n", z);//z=1
     x = 3 ;
     y = ++x -1;   printf("x=%d,y=%d/n", x , y);//x=4,y=3
     z = x--+1 ;   printf("x=%d,z=%d/n", x , z);//x=3,z=5
   }
 3. 求出下列表达式的值
 假设 x = 3, y = 4, z = 4 
 (1) (z >= y >= x)? 1 : 0   
 (2) z>=y && y>=x
 假设 x = 3, y = 2, z = 1
 (3)  x < y ? x++ : y++    
 (4)  z +=(x < y? x++ : y++)