- //
- // main.c
- // HomeWork_01
- //
- // Created by 蒋伟 on 16/5/12.
- // Copyright (c) 2016年 蒋伟. All rights reserved.
- //
- #include <stdio.h>
- int quDeMax(int num1,int num2);
- int siSheWuRu(float num);
- void panDuanChengNian(int age);
- void panDuanRunNian(int year);
- int quTianShu(int year,int mouth);
- void panDuan5WeiShu(int num);
- int quLeiJiaHe(int min,int max);
- void panDuan3BeiShu(int num);
- void panDuanZhengShu(float num);
- char fenDengJi(int score);
- int quJiShuLeiJiaHe(int min,int max);
- int main(int argc, const char * argv[]) {
-
- printf("请输入两个数以比较大小:");
- int num1,num2;
- scanf("%d%d",&num1,&num2);
- int max1 = quDeMax(num1,num2);
- printf("两者之间较大的是:%d\n\n",max1);
-
- printf("请输入一个浮点数进行四舍五入:");
- float num3;
- scanf("%f",&num3);
- int result = siSheWuRu(num3);
- printf("%.2f四舍五入的结果为:%d\n\n",num3,result);
-
- printf("请输入您的年龄以判断您是否成年:");
- int age;
- scanf("%d",&age);
- panDuanChengNian(age);
- printf("\n");
-
- printf("请输入一个年份以判断是否是闰年:");
- int year;
- scanf("%d",&year);
- panDuanRunNian(year);
- printf("\n");
-
- printf("请输入年份和月份查询此月的天数:");
- int year2,mouth2;
- scanf("%d%d",&year2,&mouth2);
- int day = quTianShu(year2,mouth2);
- printf("%d年%d月有%d天!\n\n",year2,mouth2,day);
-
- printf("请输入一个5位数以判断各位数加起来是不是5:");
- int num4;
- scanf("%d",&num4);
- panDuan5WeiShu(num4);
- printf("\n");
-
- printf("请输入范围以求累加和:");
- int min2,max2;
- scanf("%d%d",&min2,&max2);
- int sum2 = quLeiJiaHe(min2,max2);
- printf("累加的和为:%d\n\n",sum2);
-
- printf("请输入一个整数判断是否是3的倍数:");
- int num5;
- scanf("%d",&num5);
- panDuan3BeiShu(num5);
- printf("\n");
-
- printf("请输入一个数判断是否是正数:");
- float num6;
- scanf("%f",&num6);
- panDuanZhengShu(num6);
- printf("\n");
-
- printf("请输入您的成绩:");
- int score;
- scanf("%d",&score);
- char result2 = fenDengJi(score);
- printf("您获得的等级是:%c\n\n",result2);
-
- printf("请输入范围以求奇数累加和:");
- int min3,max3;
- scanf("%d%d",&min3,&max3);
- int sum3 = quJiShuLeiJiaHe(min3,max3);
- printf("奇数累加的和为:%d\n\n",sum3);
- return 0;
- }
- /**
- *取两个整数的最大值
- */
- int quDeMax(int num1,int num2){
- if(num1>=num2){
- return num1;
- }else{
- return num2;
- }
- }
- /**
- *返回浮点数四舍五入的整数
- */
- int siSheWuRu(float num){
- int zheng = (int)num;
- float fen = num - zheng;
- if(fen >= 0.5){
- zheng++;
- }
- return zheng;
- }
- /**
- *判断是否成年
- */
- void panDuanChengNian(int age){
- if(age>=18){
- printf("您已成年!\n");
- }else{
- printf("您未成年!\n");
- }
- }
- /**
- *判断年份是否为闰年
- */
- void panDuanRunNian(int year){
- if(year%400==0 ||(year%100!=0&&year%4==0)){
- printf("%d年是闰年!\n",year);
- }else{
- printf("%d年不是闰年!\n",year);
- }
- }
- /**
- *返回该年月的天数
- */
- int quTianShu(int year,int mouth){
- switch(mouth){
- case 1: case 3: case 5: case 7: case 8: case 10: case 12:
- return 31;
- break;
- case 4: case 6: case 9: case 11:
- return 30;
- break;
- case 2:
- if(year%400==0||(year%100!=0&&year%4==0)){
- return 29;
- }else{
- return 28;
- }
- default:
- return 0;
- }
- }
- /**
- *判断5位数的五位加起来等不等于5
- */
- void panDuan5WeiShu(int num){
- int g = num%10;
- int s = num/10%10;
- int b = num/100%10;
- int q = num/1000%10;
- int w = num/10000;
- if(g+s+b+q+w == 5){
- printf("%d五位数的各位数和为五。\n",num);
- }else{
- printf("%d五位数的各位数和不为五。\n",num);
- }
- }
- /**
- *返回min-max范围内整数的累加和
- */
- int quLeiJiaHe(int min,int max){
- int sum = 0;
- for(int i = min; i <= max; i++){
- sum+=i;
- }
- return sum;
- }
- /**
- *判断整数是不是3的倍数
- */
- void panDuan3BeiShu(int num){
- if(num%3 == 0){
- printf("%d是3的倍数\n",num);
- }else{
- printf("%d不是3的倍数\n",num);
- }
- }
- /**
- *判断一个数是不是正数
- */
- void panDuanZhengShu(float num){
- if(num > 0){
- printf("%.2f是正数!\n",num);
- }else{
- printf("%.2f不是正数!\n",num);
- }
- }
- /**
- *返回分数所在等级
- */
- char fenDengJi(int score){
- if(score >= 90){
- return 'A';
- }else if(score >= 80){
- return 'B';
- }else if(score >= 70){
- return 'C';
- }else if(score >= 60){
- return 'D';
- }else{
- return 'E';
- }
- }
- /**
- *返回min-max的奇数和
- */
- int quJiShuLeiJiaHe(int min,int max){
- int sum;
- for(int i = min; i <= max; i++){
- if(i%2 == 1){
- sum+=i;
- }
- }
- return sum;
- }
复制代码
|
|