day4 作业

 1. 整理思维导图

2. 终端输入三个数,判断是否能构成三角形,如果能,判断是否是等腰三角形,如果是等要三角形判断是否是等边三角形

  1 #include 
  2 #include 
  3 #include 
  4 
  5 int main(int argc, const char *argv[])
  6 {
  7     int a, b , c;
  8     printf("请输入三角的3条边:\n");
  9     scanf("%d%d%d", &a, &b, &c);
 10 
 11 
 12     if((a+b)>c && (a+c)>b &&(b+c)>a){
 13         printf("满足三角形条件\n");
 14 
 15         if (a==b||b==c||a==c){
 16             printf("满足等腰三角形条件\n");
 17 
 18             if(a==b && b==c){
 19                 printf("满足等边三角形条件\n");                                                       
 20 
 21             }
 22 
 23         }
 24     }else{
 25         printf("不满足三角形条件\n");
 26 
 27 
 28     }
 29 
 30     return 0;
 31 }

3. 终端输入年份和月份,判断该月共多少天,需要考虑闰平年

 

#include 
#include 

int main(int argc, const char *argv[])
{
	int year, month, days, is_leap_year;
	printf("请输入一个年份和月份\n");
	scanf("%d%d", &year, &month);



	if((year%4 == 0 && year%100!=0) || year%400 ==0) {
		is_leap_year = 1;
		printf("这是一个润年!\n");
	
	}else{
		is_leap_year = 0;
		printf("这不是一个润年!\n");
	
	}

	switch(month){
	case 1:
		days = 31;

		break;
	case 2:

		if(is_leap_year){
			days = 29;
		}else{
			days = 28;
		}
		break;

	case 3:
		days = 31; 	
		break;

	case 4:
		days = 30;

		break;

	case 5:
		days = 31;
		break;

	case 6:
		days = 30;
		break;

	case 7:
		days = 31;

		break;

	case 8:
		days = 31;
		break;

	case 9:
		days = 30;
		break;

	case 10:
		days = 31;
		break;
	case 11:
		days = 30;
		break;

	case 12:
		days = 31;

		break;
	
	}

	printf("这个月的天数%d\n", days);

	return 0;
}

 

4.终端输入一个数,判断是否是3的倍数,如果是3的倍数,再判断是否是7的倍数,如果是偶数,判断是否是6的倍数

#include 
#include 
#include 

int main(int argc, const char *argv[])
{
	int num;
	printf("please input a num:\n");
	scanf("%d", &num);

	if(num%3 == 0){
		printf("是3的倍数\n");

		if(num%7 == 0){
			printf("是7的倍数\n");
		
		}
	}

	if(num%2 == 0){
		printf("是偶数\n");

		if(num%6 == 0){
		printf("是6的倍数\n");
		}
	}

	return 0;
}

你可能感兴趣的:(c语言)