程序设计与c语言教案,C语言程序设计教案
读未来百家号
}
程序运行结果:
This is a C program.
[案例1.2] 由main()函数和1个其它函数max()构成的C语言程序。
/*案例代码文件名:AL1_2.C*/
/*功能:由main()函数和1个其它函数max()构成的C语言程序示例*/
int max(int x, int y)
{ return( x>y ? x : y ); }
main()
{ int num1,num2;
printf(“Input the first integer number: ”);
scanf(“%d”, &num1);
printf(“Input the second integer number: ”);
scanf(“%d”, &num2);
printf(“max=%d ”, max(num1, num2));
}
程序运行情况:
Input the first integer number:6←┘
Input the second integer number:9←┘
max=9
[案例1.3] 改写[案例1.2],交换main()函数和max()函数的前后位置。
源程序略。
程序运行情况:
Input the first integer number:6←┘
Input the second integer number:9←┘
max=9
1.函数是C语言程序的基本单位。
main()函数的作用,相当于其它高级语言中的主程序;其它函数的作用,相当于子程序。
2.C语言程序总是从main()函数开始执行。
一个C语言程序,总是从main()函数开始执行,而不论其在程序中的位置。当主函数执行完毕时,亦即程序执行完毕。
读未来百家号 } 程序运行结果: This is a C program. [案例1.2] 由main()函数和1个其它函数max()构成的C语言程序。 /*案例代码文件名:AL1_2.C*/ /*功能:由main()函数和1个其它函数max()构成的C语言程序示例*/ int max(int x, int y) { return( x>y ? x : y ); } main() { int num1,num2; printf(“Input the first integer number: ”); scanf(“%d”, &num1); printf(“Input the second integer number: ”); scanf(“%d”, &num2); printf(“max=%d ”, max(num1, num2)); } 程序运行情况: Input the first integer number:6←┘ Input the second integer number:9←┘ max=9 [案例1.3] 改写[案例1.2],交换main()函数和max()函数的前后位置。 源程序略。 程序运行情况: Input the first integer number:6←┘ Input the second integer number:9←┘ max=9 1.函数是C语言程序的基本单位。 main()函数的作用,相当于其它高级语言中的主程序;其它函数的作用,相当于子程序。 2.C语言程序总是从main()函数开始执行。 一个C语言程序,总是从main()函数开始执行,而不论其在程序中的位置。当主函数执行完毕时,亦即程序执行完毕。