绪论

第一个C程序

#include <stdio.h>

int main()
{
	printf("Hello World!\n");

	return 0;
}

![[assets/Pasted image 20240106121810.png]]

程序框架

#include <stdio.h>

int main()
{

	return 0;
}

![[assets/Pasted image 20240106110120.png]]

  • printf("Hello World!\n");
  • ""里面的内容叫做"字符串", printf会把其中的内容原封不动的输出
  • \n表示需要在输出的结果后面换一行
#include <stdio.h>

int main()
{
	printf("Hello World!\n")
	;

	return 0;
}

可以把;号放到下一行或者中间加一个空格,这样也是对的
程序出错不一定是当前行的问题,也可能是上下行出错

做计算

#include <stdio.h>

int main()
{
	printf("23+43=%d\n", 23+43);

	return 0;
}
  • printf("%d\n", 23+43);
  • %d说明后面有一个整数要输出在这个位置上
  • printf("23+43=%d\n", 2+43);
    ![[assets/Pasted image 20240106122058.png]]

四则运算

四则运算 C符号 意义
+ +
- -
× *
÷ /
% 取余
() () 括号
posted @ 2024-02-16 10:39  ChangJianhui  阅读(17)  评论(0)    收藏  举报