c-选择

#include <stdio.h>
#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


//求每一年的天,月数


bool isleap(int year){
if(((year % 4==0)&&year%100 !=0) ||(year %400==0)){
return true;
}
return false; 
}
int Getday(int year, int month){
int day;//单独给day分配个空间,因为主函数的day不是这个day 


switch(month){
case 1: //case后必须是常量整数。无论是数还是表达式,必须是常量整型 
day = 31;
break;
case 2:
if(isleap(year)){
return day = 29;
}else{
return day = 28; 


break;
case 3: 
day = 31;
break;
case 4:
day = 30;
break;
case 5:
day = 31;
break;
case 6:
day = 30;
break;
case 7:
day = 31;
break;
case 8:
day = 31;
break;
case 9:
day = 30;
break;
case 10:
day = 31;
break;
case 11:
day = 30;
break;
case 12:
day = 31;
break;
}
return day;
}
int main(){
int year;

int month;


printf("please input the year and the month !\n");
scanf("%d%d",&year,&month);//如果在%d后加\n,在结果输出是,在手动输入year和month之后,还要继续输入除空格和回车之外的键才可以有结果。 


int day = Getday(year,month);


printf("day = %d\n",day); 
return 0;

 
/*
//8.短路求值一定要谨慎 
int main(){
int i = 1;
int j = 1;
int a =0;
int value = a&&i++;//短路求值 
int value1 = a&&++j; 
printf("value = %d\n",value);//0
printf("i = %d\n",i);//1,原因是a=0,与后就不需要在计算了,因为无论&&后为什么,value一定为0;所以i仍为1; 
printf("j = %d\n",j);//1,
return 0;
}


/*
//7.简化版求闰年 
bool isleap(int year){
if(((year % 4==0)&&year%100 !=0) ||(year %400==0)){
return true;
}
return false; 
}
int main(int argc, char *argv[]){
int year;
// bool flage;
printf("please input the year!\n");
scanf("%d",&year);
bool flage = isleap(year);
if (flage){
printf("This year is leap year!\n");
}else{
printf("This year is not leap year!\n");
}
return 0;







/*
//6.判断润年:
//1.能被4整除,但不能被100整除都是润年 1996,2008,2012 
//2.能被400整除的年份是闰年 ,如1600,2000 
bool isleap(int year){
if(year % 4==0){
if(year % 100==0){
if(year % 400==0){
return true;
}
else{
return false;
}
}
else{
return true;
}
}
return false; 
}
int main(int argc, char *argv[]){
int year;
// bool flage;
printf("please input the year!\n");
scanf("%d",&year);
bool flage = isleap(year);
if (flage){
printf("This year is leap year!\n");
}else{
printf("This year is not leap year!\n");
}
return 0;





/* 
//5 3个以上的最值求解
int max(int a, int b){
return a>b?a:b;//if a>b is true, result = a;else result = b.

void main(){
int a;
int b;
int c;
int result;

printf("please input a,b,c:>\n");
scanf("%d%d%d",&a,&b,&c);

result = max(max(a,b),c);

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

//求每一年的天,月数

bool isleap(int year){
if(((year % 4==0)&&year%100 !=0) ||(year %400==0)){
return true;
}
return false;
}
int Getday(int year, int month){
int day;//单独给day分配个空间,因为主函数的day不是这个day

switch(month){
case 1: //case后必须是常量整数。无论是数还是表达式,必须是常量整型
day = 31;
break;
case 2:
if(isleap(year)){
return day = 29;
}else{
return day = 28;
}

break;
case 3:
day = 31;
break;
case 4:
day = 30;
break;
case 5:
day = 31;
break;
case 6:
day = 30;
break;
case 7:
day = 31;
break;
case 8:
day = 31;
break;
case 9:
day = 30;
break;
case 10:
day = 31;
break;
case 11:
day = 30;
break;
case 12:
day = 31;
break;
}
return day;
}
int main(){
int year;
int month;
printf("please input the year and the month !\n");
scanf("%d%d",&year,&month);//如果在%d后加\n,在结果输出是,在手动输入year和month之后,还要继续输入除空格和回车之外的键才可以有结果。
int day = Getday(year,month);

printf("day = %d\n",day);
return 0;
}

/*
//8.短路求值一定要谨慎
int main(){
int i = 1;
int j = 1;
int a =0;
int value = a&&i++;//短路求值
int value1 = a&&++j;
printf("value = %d\n",value);//0
printf("i = %d\n",i);//1,原因是a=0,与后就不需要在计算了,因为无论&&后为什么,value一定为0;所以i仍为1;
printf("j = %d\n",j);//1,
return 0;
}

/*
//7.简化版求闰年
bool isleap(int year){
if(((year % 4==0)&&year%100 !=0) ||(year %400==0)){
return true;
}
return false;
}
int main(int argc, char *argv[]){
int year;
// bool flage;
printf("please input the year!\n");
scanf("%d",&year);
bool flage = isleap(year);
if (flage){
printf("This year is leap year!\n");
}else{
printf("This year is not leap year!\n");
}
return 0;
}



/*
//6.判断润年:
//1.能被4整除,但不能被100整除都是润年 1996,2008,2012
//2.能被400整除的年份是闰年 ,如1600,2000
bool isleap(int year){
if(year % 4==0){
if(year % 100==0){
if(year % 400==0){
return true;
}
else{
return false;
}
}
else{
return true;
}
}
return false;
}
int main(int argc, char *argv[]){
int year;
// bool flage;
printf("please input the year!\n");
scanf("%d",&year);
bool flage = isleap(year);
if (flage){
printf("This year is leap year!\n");
}else{
printf("This year is not leap year!\n");
}
return 0;
}


/*
//5.3个以上的最值求解
int max(int a, int b){
return a>b?a:b;//if a>b is true, result = a;else result = b.
}
void main(){
int a;
int b;
int c;
int result;

printf("please input a,b,c:>\n");
scanf("%d%d%d",&a,&b,&c);
result = max(max(a,b),c);
printf("max value is %d! \n",result);
//result = a>b?b:a;
//printf("min value is %d! \n",result);
}

/*
// 4.函数方式的三目运算符求最值
int max(int a, int b){
return a>b?a:b;//if a>b is true, result = a;else result = b.
}
void main(){
int a;
int b;
int result;

printf("please input a,b:>\n");
scanf("%d%d",&a,&b);
result = max(a,b);
printf("max value is %d! \n",result);
//result = a>b?b:a;
//printf("min value is %d! \n",result);
}
/* //3.三目运算符 2个数求max
void main(){
int a;
int b;
int result;

printf("please input a,b:>\n");
scanf("%d%d",&a,&b);
result = a>b?a:b;//if a>b is true, result = a;else result = b.
printf("max value is %d! \n",result);
//result = a>b?b:a;
//printf("min value is %d! \n",result);
}
/* //2.max
void main(){
int a;
int b;
int c;
int result;
printf("please input a,b,c:>\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
result = a;
}
else if(b>a&&b>c){
result = b;
}
else {
result = c;
}

printf("%d\n",result);
}

/* //1
int main(int argc, char *argv[]) {
int a,b,c;
printf("please input the value of the a,b,c:>\n");
scanf("%d,%d,%d",&a,&b,&c);
printf("a = %d,b = %d,c = %d",a,b,c);
return 0;
}
*/

printf("max value is %d! \n",result);
//result = a>b?b:a;
//printf("min value is %d! \n",result);
}  


/* 
// 4.函数方式的三目运算符求最值
int max(int a, int b){
return a>b?a:b;//if a>b is true, result = a;else result = b.

void main(){
int a;
int b;
int result;

printf("please input a,b:>\n");
scanf("%d%d",&a,&b);
result = max(a,b);
printf("max value is %d! \n",result);
//result = a>b?b:a;
//printf("min value is %d! \n",result);

/* //3.三目运算符 2个数求max 
void main(){
int a;
int b;
int result;

printf("please input a,b:>\n");
scanf("%d%d",&a,&b);
result = a>b?a:b;//if a>b is true, result = a;else result = b.
printf("max value is %d! \n",result);
//result = a>b?b:a;
//printf("min value is %d! \n",result);
}
/* //2.max
void main(){
int a;
int b;
int c;
int result;
printf("please input a,b,c:>\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
result = a; 

else if(b>a&&b>c){
result = b;
}
else {
result = c;
}

printf("%d\n",result);



/* //1 输入输出函数
int main(int argc, char *argv[]) {
int a,b,c;
printf("please input the value of the a,b,c:>\n");
scanf("%d,%d,%d",&a,&b,&c);
printf("a = %d,b = %d,c = %d",a,b,c);
return 0;
}
*/ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值