C语言课堂小记

//
// Created by hengxin on 9/30/22.
//

#include <stdio.h>
int main() {
  // const: constant
  const double PI = 3.14159;
  int radius = 10;

  double circumference = 2 * PI * radius;
  double area = PI * radius * radius;

  printf("circumference = %.2f\narea = %.2f\n",
         circumference, area);

  return 0;
}

This code calculates the circumference and area of a circle with a given radius and prints the results.

1.The code includes the &lt;stdio.h&gt; header file, which provides functions for input and output operations.
2.The main() function is the entry point of the program.
3.A constant double variable PI is declared and assigned the value 3.14159. The const keyword is used to indicate that the value of PI cannot be changed.
4.An int variable radius is declared and assigned the value 10.
5.The circumference of the circle is calculated using the formula 2 * PI * radius, and the result is stored in the double variable circumference.
6.The area of the circle is calculated using the formula PI * radius * radius, and the result is stored in the double variable area.
7.The printf() function is used to print the values of circumference and area with two decimal places. The format specifier %.2f is used to specify the precision of the floating-point numbers.
8.The resulting output is "circumference = [value]\narea = [value]", where [value] represents the actual calculated values of circumference and area.
9.Finally, the return 0 statement indicates that the program execution completed successfully.
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cytingle

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值