从今天开始,我将C语言的代码实例从发表在博客上。供技术交流。比较基础,遵循循序渐进的原则,由简单到复杂,为以后的程序员生涯打好基础。
1.编写一个C程序输出以下信息。
*****************
Very Good!
*****************
代码如下:
# include
int main(void) {
printf("*****************\n") ;
printf(" Very Good! \n") ;
printf("*****************\n") ;
return 0 ;
}
2.求两个数中的较大者
代码如下:
# include
int main(void) {
int max(int x,int y) ; //引入下面定义的函数max(int x,int y) ;
int a,b,c ; //定义变量
scanf("%d,%d",&a,&b) ; //键盘上输入参数
c = max(a,b) ; //将最大的值保存在变量C当中
printf("%d\n",c) ; //打印输出最大值
return 0 ;
}
int max(int x,int y) { //定义求最大值的函数
int z ;
if(x > y){
z = x ;
} else {
z = y ;
}
return z ;
}
3.输入三个数,比较其中的最大值。
# include
int main(void) {
int max(int x,int y,int z) ; //声明函数的名称
int a,b,c,result ; //定义变量
scanf("%d,%d,%d",&a,&b,&c) ; //从键盘上输入
result = max(a,b,c) ; //将最大的值的结果赋值给result
printf("The max number is %d\n",result) ;//输出最大值
return 0 ;
}
int max(int x,int y,int z) { //处理最最大值的函数 int temp ; temp = x ; if(temp < y) { temp = y ; } else if(temp < z) { temp = z ; } return temp ; }
更多推荐
c语言分手代码大全,C语言代码大全
发布评论