C语言入门课程学习笔记1
- 第1课 - 概论
- 第2课 -helloworld
- 第3课 -数据输出
- 第4课 -数据类型与变量
- 第5课 - 深入数据类型与变量
- 第6课 - 类型与变量编程练习
- 第7课 - 程序中的数据输入
本文学习自狄泰软件学院 唐佐林老师的 C语言入门课程,图片全部来源于课程PPT,仅用于个人学习记录
第1课 - 概论
第2课 -helloworld
C程序从main()开始执行,基本执行单位为语句
C程序默认情况下自上向下顺序执行
C程序为单纯的文本文件,无法直接执行
C程序编译后可生成二进制可执行程序
第3课 -数据输出
#include <stdio.h>int main()
{printf("%s\n", "Hello, world!");printf("%s = %d\n", "1 + 1", 1 + 1);printf("D.T.Software\n");return 0;
}
第4课 -数据类型与变量
#include <stdio.h>int main()
{printf("%d\n", 2);printf("%f\n", 2.0);printf("%c\n", '2');return 0;
}
第5课 - 深入数据类型与变量
#include <stdio.h>int main()
{int a = 50000;short b = 0;int i = 0;float f = 0.2;printf("a = %d\n", a);printf("b = %d\n", b);printf("\n");b = a;printf("a = %d\n", a);printf("b = %d\n", b);printf("\n");b = 30000;a = b;printf("a = %d\n", a);printf("b = %d\n", b);printf("\n");printf("\n");printf("i = %d\n", i);printf("f = %f\n", f);printf("\n");f = 3.14f;i = f;printf("i = %d\n", i);printf("f = %f\n", f);return 0;
}/*output:
a = 50000
b = 0a = 50000
b = -15536a = 30000
b = 30000i = 0
f = 0.200000i = 3
f = 3.140000*/
#include <stdio.h>int main()
{int a = 50000;short b = 0;int i = 0;float f = 0.2;i = 40000;b = (short)i;printf("i = %d\n", i);printf("b = %d\n", b);printf("\n");f = 3.1415f;a = (int)f;printf("f = %f\n", f);printf("a = %d\n", a);return 0;
}/*output:
i = 40000
b = -25536f = 3.141500
a = 3*/
第6课 - 类型与变量编程练习
#include <stdio.h>int main()
{int a = 10;int b = 20;int c;printf("a = %d\n", a);printf("b = %d\n", b);printf("\n");c = a;a = b;b = c;printf("a = %d\n", a);printf("b = %d\n", b);return 0;
}
#include <stdio.h>int main()
{float f = 1.49f;float r = 0;r = f + 0.5f;r = (int)r;printf("f = %f\n", f);printf("r = %f\n", r);return 0;
}
第7课 - 程序中的数据输入
#include <stdio.h>int main()
{float i = 0;printf("i = %f\n", i);scanf("%f", &i);printf("i = %f\n", i);return 0;
}/*output:
i = 0.000000
34
i = 34.000000*/
#include <stdio.h>int main()
{int i = 0;int j = 0;int k = 0;printf("Input 2 numbers to add:\n");scanf("%d%d", &i, &j);k = i + j;printf("%d + %d = %d\n", i, j, k);return 0;
}/*output:
Input 2 numbers to add:
23 34
23 + 34 = 57*/