记录一下自己刚才学习的C语言知识点
2018-12-27 19:25:02
用代码说明自己所学习到的内容多好啊!
-------------------------
/*program 1.0*/ 注释写法
#include <stdio.h> 预处理 头文件
void main() 主函数
{
int a=45,b=7,c=0; 定义变量
printf("a+b=%d\n",c=a+b); 加法运算
printf("a-b=%d\n",c=a-b); 减法运算
printf("a*b=%d\n",c=a*b); 乘法运算
printf("a/b=%d\n",c=a/b); 除法运算
printf("a%%b=%d\n",c=a%b); 取模运算
system("pause"); 暂停
}
---------------------------
% 这是格式说明符,也叫格式转换符。
%d 输出整型值
%f 输出浮点值(有小数点的)
%.2f/d 输出小数点后2位的浮点值或整型值。
#include <stdio.h>
#define PI 3.14159f 定义常量 PI必须大写
void main()
{
float radius=0.0f;
float diameter=0.0f;
float circumference=0.0f;
float area=0.0f;
printf("Input the diameter of the table:");
scanf("%f",&diameter);
radius=diameter/2.0f;
printf("\nThe circumference is %.2f",2.0f*PI*radius); 参数二,可以是表达式
printf("\nThe area is %.2f\n",PI*radius*radius);
system("pause");
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步