C语言简单代码作业练习


// 求两个数的最小值
// #include <stdio.h>
// int main(){
//     int a,b,min;
//     scanf("%d%d", &a, &b);
//     min = a<b ? a : b;
//     printf("两者当中较小的为:%d", min);
//     return 0;
// }


// // 从小到大排序
// #include <stdio.h>
// int main(){
//     int a,b,c,t;
//     scanf("%d%d%d", &a, &b, &c);
//     if (a>b)
//     {   t=a; a=b; b=t;}
//     if (a>c)
//     {   t=a; a=c; c=t;}
//     if (b>c)
//     {   t=b; b=c; c=t;}
//     printf("The sorted number is: %d < %d < %d", a, b, c);
//     return 0;
// }


// 求一元二次方程的解
// #include <stdio.h>
// #include <math.h>
// int main(){
//     double a,b,c,disc,x1,x2,realpart,imagpart;
//     scanf("%lf,%lf,%lf", &a, &b, &c);
//     disc = b*b - 4*a*c;
//     if (fabs(disc) < 1e-6)
//         printf("has two equal roots:%8.4lf\n", -b/(2*a));
//     else if (disc > 1e-6)
//         {
//             x1 = (-b + sqrt(disc))/(2*a);
//             x2 = (-b - sqrt(disc))/(2*a);
//             printf("has distinct real roots:%8.4lf and %8.4lf\n", x1, x2);
//         }
//     else
//         {
//             realpart = -b/(2*a);
//             imagpart = sqrt(-disc) / (2*a);
//             printf("has complex roots:\n");
//             printf("%8.4lf+%8.4lf i \n", realpart, imagpart);
//             printf("%8.4lf-%8.4lf i \n", realpart, imagpart);
//         }


//     return 0;
// }


// 学生成绩百分制换成5分制
// #include <stdio.h>
// int main(){
//     double score;
//     scanf("%lf", &score);
//     printf("百分制分数:%lf\n", score);
//     if (score<0 || score >100)
//         printf("error!\n");
//     else if (score<=100 && score>=90){
//         printf("A\n");
//     }
//     else if (score>=80){
//         printf("B\n");
//     }
//     else if (score>=70){
//         printf("C\n");
//     }
//     else if (score>=60){
//         printf("D\n");
//     }
//     else if (score>=0){
//         printf("E\n");
//     }
//     return 0;
// }


// #include <stdio.h>

// int main()
// {
//     int year, month, day, flag=1,a=6;
//     scanf("%d%d", &year, &month);
//     if (month == 2)
//         {
//         if ((year%4==0 && year%100!=0)||(year%400==0))
//                 day=29;
//         else
//                 day=28;
//         }
//     else
//         switch(month)
//         {
//             case 1:
//             case 3:
//             case 5:
//             case 7:
//             case 8:
//             case 10:
//             case 12: day = 31;break;
//             case 4:
//             case 6:
//             case 9:
//             case 11: day = 30;break;
//             default:printf("Data error!\n");flag=0;
//         }
//     if (flag)
//         printf("%d年%d月有%d天。\n", year, month, day);
//     else
//         printf("Data error!\n");

//     return 0;
// }


// #include <stdio.h>

// int main()
// {
//     if (1+1)
//         printf("A");
//     return 0;
// }


// 大小写转换
// #include <stdio.h>

// int main()
// {
//     char ch;
//     scanf("%c", &ch);
//     printf("输入的字母是:%c\n", ch);
    
//     if (ch>='a' && ch<='z')
//         ch = ch - 32;
//     else if (ch>='A' && ch<='Z')
//         ch = ch + 32;
//     printf("输出的字母是:%c\n", ch);
//     return 0;
// }

// #include <stdio.h>
// int main()
// {   
//     char ch;
//     printf("请输入一个大写字母:\n");
//     scanf("%c", &ch);
//     if (ch<'A'||ch>'Z')
//         printf("输入错误!");
//     else
//         if (ch == 'A')
//             printf("没有前面的字母");
//         else if (ch == 'Z')
//             printf("没有后面的字母");
//         else
//             printf("%c, %c", ch-1, ch+1);
//     return 0;
// }


#include <stdio.h>
int main(){

    // // ---------------学生成绩百分制换成5分制
    // double score;
    // scanf("%lf", &score);
    // printf("百分制分数:%lf\n", score);
    // if (score<0 || score >100)
    //     printf("error!\n");
    // else if (score<=100 && score>=90){
    //     printf("A\n");
    // }
    // else if (score>=80){
    //     printf("B\n");
    // }
    // else if (score>=70){
    //     printf("C\n");
    // }
    // else if (score>=60){
    //     printf("D\n");
    // }
    // else if (score>=0){
    //     printf("E\n");
    // }

    // // ---------------输出明天的日期
    // int year, month, day;
    // printf("输入今天的日期:\n");
    // scanf("%d%d%d", &year, &month, &day);
    // switch(month)
    // {
    //     case 1:
    //     case 3:
    //     case 5:
    //     case 7:
    //     case 8:
    //     case 10:
    //     case 12:if (day == 31)
    //                 printf("明天的日期为:%d年%d月%d日", year, month+1, 1);
    //             else
    //                 printf("明天的日期为:%d年%d月%d日", year, month, day+1);
    //             break;
    //     case 4:
    //     case 6:
    //     case 9:
    //     case 11:if (day == 30)
    //                 printf("明天的日期为:%d年%d月%d日", year, month+1, 1);
    //             else
    //                 printf("明天的日期为:%d年%d月%d日", year, month, day+1);
    //             break;
    //     case 2:if ((year%4==0 && year%100!=0)||(year%400==0))
    //                 if (day == 29)
    //                     printf("明天的日期为:%d年%d月%d日", year, month+1, 1);
    //                 else
    //                     printf("明天的日期为:%d年%d月%d日", year, month, day+1);
    //             else
    //                 if (day == 28)
    //                     printf("明天的日期为:%d年%d月%d日", year, month+1, 1);
    //                 else
    //                     printf("明天的日期为:%d年%d月%d日", year, month, day+1);
    //             break;
    //     default:printf("输入错误!");
    // }
   
    // ---------------三角形判定
    double a, b, c, t;
    printf("请输入三条线段的长度:");
    scanf("%lf,%lf,%lf", &a, &b, &c);
        // 先排序
    if (a>b)
        {   t=a; a=b; b=t;}
    if (a>c)
        {   t=a; a=c; c=t;}
    if (b>c)
        {   t=b; b=c; c=t;}
    printf("%lf, %lf, %f\n", a, b, c);
    if (((a+b)>c)&&((c-b)<a))
        if ((a==b)&&(b==c))
            printf("等边三角形");
        else if (((a==b)&&(b!=c))||(b==c)&&(a!=b))
            printf("等腰三角形");
        else if (a*a + b*b == c*c)
            printf("直角三角形");
        else
            printf("任意三角形");
    else
        printf("不能构成三角形");


    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值