first commit

This commit is contained in:
flykhan 2023-06-02 02:41:24 +08:00
parent 6b95ca5582
commit edc6966b9d
No known key found for this signature in database
20 changed files with 309 additions and 0 deletions

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

View File

@ -0,0 +1,28 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
// 定义一个char类型的变量并赋值输出字符使用c%
char a = 'w';
printf("a = %c\n",a);
// 定义一个short类型的变量并赋值
short b = 100;
printf("b = %d\n",b);
// 定义一个int类型的变量并赋值输出int类型变量的值使用%d
int c = 9999;
printf("c = %d\n",c);
// 定义一个long类型的变量并赋值输出long类型变量的值使用%ld
long d = 2342341;
printf("d = %ld\n",d);
float e = 3.1415926;
printf("e = %f\n",e);
double f = 3234.234214342345;
printf("f = %lf\n",f);
return 0;
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/05_printf.iml" filepath="$PROJECT_DIR$/.idea/05_printf.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="31f10055-069d-473b-9478-0309bc257748" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="formatViaClangd" value="false" />
</component>
<component name="ProjectId" id="2QQgIoSTflB0TzMXNpGO2ORQeSd" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"WebServerToolWindowFactoryState": "false",
"cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true",
"last_opened_file_path": "D:/GitHome/QianFeng/C_lang/05_printf",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="31f10055-069d-473b-9478-0309bc257748" name="Changes" comment="" />
<created>1685291143580</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1685291143580</updated>
<workItem from="1685291144185" duration="50000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

46
1_lesson/05_printf/main.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
int a = 100;
printf("a = %d\n",a);
printf("a = %o\n",a); // 八进制输出
printf("a = %#o\n",a); // %#o 可以输出八进制数的前导符
printf("a = %x\n",a); // 十六进制输出
printf("a = %#x\n",a);
// 输出浮点型数据,float使用%f,double使用%lf
float b = 3.1415926;
double c = 2345.2345;
printf("b = %f\n",b);
printf("c = %lf\n",c);
// 输出字符,使用%c使出字符使用%d可以输出字符的ascii码值
char d = 'y';
printf("d = %c %d\n",d,d);
char e[] = "hello world";
printf("e = %s\n",e);
// 输出地址,使用%p
int f = 999;
// &:取一个变量的地址,一般地址用十六进制标识
printf("&p = %#p\n", &f); // 获取当前变量的地址用 %p
int m = 456;
printf("%d%d\n", m, m);
printf("%5d%5d\n", m, m);
// %05d:输出的宽度为5右对齐如果实际数据的宽度小于5则左边位置补0
printf("%05d%05d\n", m, m);
//%-5d:输出的宽度为5左对齐如果实际数据的宽度小于5则右边补空格
printf("%-5d%-5d\n", m, m);
float n = 3.678;
printf("n = %f\n", n);
//%.2f:小数点后保留两位,并且可以四舍五入
printf("n = %.2f\n", n);
}

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

View File

@ -0,0 +1,26 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
// 定义一个一维数组
int a[10];
// 通过sizeof关键字可以获取数组的大小
printf("sizeof(a) = %d %d\n", sizeof(a), 10* sizeof(int));
// 如果定义数组的同时赋值(初始化),可以不指定数组元素的个数
int b[] = {10, 20, 30};
printf("sizeof(b) = %d\n",sizeof(b));
printf("******************************\n");
// 定义一个二维数组
int c[2][4];
printf("sizeof(c) = %d %d\n",sizeof(c), 2 * 4 * sizeof(int));
// 二维数组的行数可以省略,但是列数不能省略,在初始化时可以这样操作
// 系统会根据列数自动指定行数,最终得到的函数所得元素个数是列的整数倍
int d[][4] = {1, 2, 3, 4, 5};
printf("sizeof(d) = %d\n",sizeof(d));
return 0;
}

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

View File

@ -0,0 +1,24 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
// 一维数组的初始化
// 如果不初始化,直接使用会是随机值
// int a[4];
// 初始化方式1全部初始化
// int a[4] = {123, 78, 666, 476};
// 如果是全部初始化,可以不指定数组元素的个数,系统会自动分配
// int a[] = {10, 20, 30, 40};
// 初始化方式2局部初始化
// 未初始化的位置的元素自动赋值为0
int a[4] = {10, 20};
printf("%d\n",a[0]);
printf("%d\n",a[1]);
printf("%d\n",a[2]);
printf("%d\n",a[3]);
return 0;
}

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

View File

@ -0,0 +1,31 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
// 二维数组的初始化
// int a[2][3];
// 初始化方式1按行初始化
// 全局初始化
// int a[2][3] = {{10, 20, 30}, {666, 777, 888}};
// 局部初始化
// 没有赋值的位置的元素自动为0
// int a[2][3] = {{10, 20}, {666}};
// 初始化方式2逐个初始化
// 全部初始化
// int a[2][3] = {1, 2, 3, 4, 5, 6};
// 局部初始化
// 没有赋值的位置的元素自动为0
int a[2][3] = {1, 2, 3};
printf("%d\n",a[0][0]);
printf("%d\n",a[0][1]);
printf("%d\n",a[0][2]);
printf("%d\n",a[1][0]);
printf("%d\n",a[1][1]);
printf("%d\n",a[1][2]);
return 0;
}

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

39
2_lesson/04_quote/main.c Normal file
View File

@ -0,0 +1,39 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
// 一维数组的引用以及一维数组的遍历
int a[6] = {111, 222, 333, 444, 555, 666};
a[3] = 10000;
// 一维数组的遍历
int i;
for(i = 0; i< sizeof(a) / sizeof(int);i++)
{
printf("a[%d] = %d\n",i,a[i]);
}
printf("************************\n");
// 二维数组的引用以及二维数组的遍历
int b[3][4] = {1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12
};
b[2][0] = 666;
// 二维数组的遍历
int m, n;
// 外层循环控制行数
for(m = 0; m < 3; m++){
// 内层循环控制列数
for(n = 0; n < 4; n++){
printf("%-4d", b[m][n]); // 宽度为4左对齐显示
}
printf("\n");
}
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.