摘要: 1、计算1到n之间的所有整数的和。 #include <stdio.h> int sum(int n) { int i; int sum = 0; for (i = 1; i <= n; i++) { sum += i; } return sum; } int main(void) { int x; 阅读全文
posted @ 2021-03-24 12:41 小鲨鱼2018 阅读(2579) 评论(0) 推荐(0) 编辑
摘要: 1、值传递,计算x的n次幂 #include <stdio.h> double power(double x, int n) { int i; double tmp = 1.0; for (i = 1; i <= n; i++) { tmp *= x; } return tmp; } int mai 阅读全文
posted @ 2021-03-24 12:24 小鲨鱼2018 阅读(1234) 评论(0) 推荐(0) 编辑
摘要: 1、计算int型整数的四次幂 #include <stdio.h> int sqr(int x) { return x * x; } int sqr2(int a) { return sqr(sqr(a)); } int main(void) { int n; puts("please input 阅读全文
posted @ 2021-03-24 11:30 小鲨鱼2018 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 1、c语言在函数中调用其他函数(计算四个数中的最大值) #include <stdio.h> int max2(int a, int b) { return (a > b) ? a : b; } int max4(int x, int y, int z, int p) { return max2(m 阅读全文
posted @ 2021-03-24 11:21 小鲨鱼2018 阅读(508) 评论(0) 推荐(0) 编辑
摘要: 1、c语言中定义函数和调用函数(计算int型整数的立方) #include <stdio.h> int cube(int a) { return a * a * a; } int main(void) { int n1; puts("please input an integer."); print 阅读全文
posted @ 2021-03-24 11:06 小鲨鱼2018 阅读(1157) 评论(0) 推荐(0) 编辑
摘要: 1、将函数的返回值作为参数传递给其他函数,计算平方差 #include <stdio.h> int sqr(int x) { return x * x; } int diff(int a, int b) { return (a > b ? a - b : b - a); } int main(voi 阅读全文
posted @ 2021-03-24 10:56 小鲨鱼2018 阅读(294) 评论(0) 推荐(0) 编辑
摘要: 1、c语言中定义函数和调用函数(计算三个数中的最小值) #include <stdio.h> int min3(int a, int b, int c) { int min = a; if (b < min) min = b; if (c < min) min = c; return min; } 阅读全文
posted @ 2021-03-24 10:41 小鲨鱼2018 阅读(3617) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int min2(int a, int b) { if (a < b) return a; else return b; } int main(void) { int n1, n2; puts("please input two integers!"); 阅读全文
posted @ 2021-03-24 10:24 小鲨鱼2018 阅读(854) 评论(0) 推荐(0) 编辑
摘要: 1、c语言中定义函数和调用函数(计算三个数中的最大值) #include <stdio.h> int max3(int a, int b, int c) { int max = a; if (b > max) max = b; if (c > max) max = c; return max; } 阅读全文
posted @ 2021-03-24 10:08 小鲨鱼2018 阅读(3592) 评论(0) 推荐(0) 编辑
摘要: 1、求两个数中的较大值 #include <stdio.h> int main(void) { int i, j, max; puts("please input two integer!"); printf("i = "); scanf("%d", &i); printf("j = "); sca 阅读全文
posted @ 2021-03-24 09:52 小鲨鱼2018 阅读(384) 评论(0) 推荐(0) 编辑
摘要: 1、函数定义和函数调用 #include <stdio.h> int max2(int a, int b) ## 函数头:返回类型, 函数名,形参声明a,形参声明b { if (a > b) return a; ## 函数体(复合语句) ## 函数定义 else return b; } int ma 阅读全文
posted @ 2021-03-24 09:26 小鲨鱼2018 阅读(633) 评论(0) 推荐(0) 编辑
摘要: 1、c语言中main函数和库函数 #include <stdio.h> int main(void) { /*.......*/ return 0; } 其中绿色部分称为main函数。 c语言程序中,main函数是必不可少的。程序运行的时候,会执行main函数的主体部分。 main函数中使用了pri 阅读全文
posted @ 2021-03-24 08:44 小鲨鱼2018 阅读(430) 评论(0) 推荐(0) 编辑