奇数偶数判断,平年闰年判断以及三角形周长面积的计算(虚拟机上的简单应用题:基于c语言的嵌入式开发)

文章介绍了如何使用C语言实现奇数偶数判断、平年闰年识别,以及利用海伦公式计算三角形周长和面积的基本程序。
摘要由CSDN通过智能技术生成

1.奇数偶数的判断

#include <stdio.h>

int main(void)
{
    int a;
    
    scanf("%d", &a);
    if (0 == a % 2)
        {
            printf("该数为偶数");
        }
    else
        {
            printf("该数为奇数");
        }
            




    return 0;
}

2.平年闰年的判断 

#include <stdio.h>

int main(void)
{
    int a;
    
    
    scanf("%d", &a);
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        {
           
                if (0 == a % 400)
                    {
                        printf("该年也为世纪闰年");
                    }
                else
                    {
                        printf("该年为闰年");
                    } 
       }
    else
        {
            printf("该数为奇数");
        }
            




    return 0;
}

3.三角形周长与面积的计算 

1.应用数学计算式要引用数学函数

   #include <math.h>

2.与此同时,在虚拟机上运行时也要编译才能运行

  gcc filename.c -lm

3.应用海伦公式

#include <stdio.h>
#include <main.h>

int main(void)
{
    double a;
    double b;
    double c;
    double C;
    double S;
    double p;
    
    scanf("%lf%lf%lf", &a, &b, &c);
    C = a + b + c;
    printf("%lf",C);
    p = (a + b + c)/2;

    S = sqrt(p * (p - a) * (p - b) * (p - c));
    printf("%lf",S);




    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值