(1)检查所用的计算机系统是否已安装了C编译系统并确定它所在的子目录。
(2)进入所用的C编译集成环境.
(3)熟悉集成环境的界面和有关菜单的使用方法。
# include
int main()
{printf ("This is a e program. \n"); return 0;
}
②仔细观察屏幕上的已输入的程序.检查有无错误。
③根据本书第3部分介绍的方法对源程序进行编译,观察屏幕上显示的编译信息。如
果出现“出错信息”,则应找出原因并改正之,再进行编译,如果无错,则进行连接。
④如果编译连接无错误,运行程序,观察分析运行结果。
#include int main()
{int a, b, suma = 123; b = 456;sum = a+bprint("sum is %d\n", sum);return 0;
}
#include int main()
{int max(int x, int y);int a, b, c;printf("input a & b:");scanf("%d,%d", &a, &b);c = max(a, b);printf("max=%d\n", c);return 0;
}int max(int x, int y)
{int z;if (x > y) z = x;else z = y;return (z);
}
int a; b; c;
再进行编译,观察其结果。
if (x > y)z = x; else z = y;
进行编译和运行,分析结果。
题目是教材第1章的第6题。即输人a,b,c 3个值,输出其中最大者。
# include
int main()
{printf ("This is a e program. \n"); return 0;
}
程序没有出现错误。
已启动重新生成…
1>------ 已启动全部重新生成: 项目: 1-C程序的运行环境和运行C程序的方法, 配置: Debug Win32 ------
1>Main.c
1>1-C程序的运行环境和运行C程序的方法.vcxproj -> E:\Document\2-programmLanguageExper\C\1-课程-C语言及算法设计实验\C语言课程实验\Debug\1-C程序的运行环境和运行C程序的方法.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
成功 1 个,失败 0 个,跳过 0 个
程序编译运结果如下
#include int main()
{int a, b, suma = 123; b = 456;sum = a+bprint("sum is %d\n", sum);return 0;
}
编译出现如下错误信息
修改之后的程序如下
#include int main()
{int a, b, sum;a = 123; b = 456;sum = a + b;printf("sum is %d\n", sum);return 0;
}
正确程序的运行结果如下
#define _CRT_SECURE_NO_WARNINGS#include int main()
{int max(int x, int y);int a, b, c;printf("input a & b:");scanf("%d,%d", &a, &b);c = max(a, b);printf("max=%d\n", c);return 0;
}int max(int x, int y)
{int z;if (x > y) z = x;else z = y;return (z);
}
编译与运行结果
编译结果如下
已启动重新生成…
1>------ 已启动全部重新生成: 项目: 1-C程序的运行环境和运行C程序的方法, 配置: Debug Win32 ------
1>Main.c
1>Main2.c
1>Main3.c
1>正在生成代码...
1>1-C程序的运行环境和运行C程序的方法.vcxproj -> E:\Document\2-programmLanguageExper\C\1-课程-C语言及算法设计实验\C语言课程实验\Debug\1-C程序的运行环境和运行C程序的方法.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
运行结果如下
int a; b; c;
再进行编译,观察其结果。
将程序中的第4行改为
int a; b; c;
之后编译运行结果,如下所示。
程序出现了: error C2065: “c”: 未声明的标识符
int a; b; c;
:说明没有定义b和c变量,只是定义了a变量。
④将max函数中的第3,4两行合并写为一行,即
if (x > y)z = x; else z = y;
将max函数中的第3,4两行合并写为一行编译运行结果如下所示
题目是教材第1章的第6题。即输人a,b,c 3个值,输出其中最大者。
编写的源程序如下所示
#define _CRT_SECURE_NO_WARNINGS#include
#include int maxFn(int a, int b, int c);int main()
{system("color 3E");int a, b, c, max;printf("input a & b & c:");scanf("%d%d%d", &a, &b, &c);max = maxFn(a, b, c);printf("max=%d\n", max);system("pause");return 0;
}int maxFn(int a, int b, int c)
{int max;max = a;if (max < b){max = b;} if(max < c){max = c;}return max;
}
编译运行程序如下所示
.c和.exe的文件如下所示
通过C语言及算法设计课程实验:C程序的运行环境和运行C程序的方法
自己掌握了如下几点
Main1.c源文件代码如下
#include
#include int main()
{system("color 3E");printf("This is a e program. \n");system("pause");return 0;
}
Main2.c源文件代码如下
#include int main()
{int a, b, sum;a = 123; b = 456;sum = a + b;printf("sum is %d\n", sum);return 0;
}
Main3.c源文件代码如下
#define _CRT_SECURE_NO_WARNINGS#include int main()
{int max(int x, int y);int a, b, c;printf("input a & b:");scanf("%d,%d", &a, &b);c = max(a, b);printf("max=%d\n", c);return 0;
}int max(int x, int y)
{int z;/*if (x > y) z = x;else z = y;*/if (x > y)z = x; else z = y;return (z);
}
MaxDigit.c源文件代码如下
#define _CRT_SECURE_NO_WARNINGS#include
#include int maxFn(int a, int b, int c);int main()
{system("color 3E");int a, b, c, max;printf("input a & b & c:");scanf("%d%d%d", &a, &b, &c);max = maxFn(a, b, c);printf("max=%d\n", max);system("pause");return 0;
}int maxFn(int a, int b, int c)
{int max;max = a;if (max < b){max = b;} if(max < c){max = c;}return max;
}