随笔分类 - c/c++
摘要:1、c语言中计算4行3列矩阵和3行4列矩阵的乘积 #include <stdio.h> int main(void) { int i, j, k; int a[4][3], b[3][4]; puts("input the array a."); for (i = 0; i < 4; i++) {
阅读全文
摘要:1、 #include <stdio.h> int main(void) { int i, j, k; int a[4][3] = {{4,2,3},{1,5,4},{2,3,1},{4,2,6}}; ## 4行3列矩阵 int b[3][4] = {{4,2,3,6},{2,4,3,5},{2,3
阅读全文
摘要:1、 c语言中求三维数组元素的和(2、4、3) #include <stdio.h> int main(void) { int i, j, k; int v[2][4][3] = {{{74,58,96},{14,25,36},{45,65,74},{45,56,96}},{{74,58,36},{
阅读全文
摘要:1、c语言中求4行3列二维数组元素的和 #include <stdio.h> int main(void) { int i, j; int a[4][3] = {{74,85,69},{14,25,36},{45,65,96},{58,47,56}}; int b[4][3] = {{45,56,7
阅读全文
摘要:1、一维数组 #include <stdio.h> #define NUMBER 6 int main(void) { int i; int v[NUMBER]; for (i = 0; i < NUMBER; i++) { printf("v[%d] = ", i); scanf("%d", &v
阅读全文
摘要:#include <stdio.h> #define NUMBER 7 int search(const int v[], int idx[], int key, int n) { int i = 0, j = 0; while (i < n) { if (v[i] == key) { idx[j]
阅读全文
摘要: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;
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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; }
阅读全文
摘要: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!");
阅读全文
摘要: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; }
阅读全文
摘要:1、求两个数中的较大值 #include <stdio.h> int main(void) { int i, j, max; puts("please input two integer!"); printf("i = "); scanf("%d", &i); printf("j = "); sca
阅读全文
摘要:1、函数定义和函数调用 #include <stdio.h> int max2(int a, int b) ## 函数头:返回类型, 函数名,形参声明a,形参声明b { if (a > b) return a; ## 函数体(复合语句) ## 函数定义 else return b; } int ma
阅读全文
摘要:1、c语言中main函数和库函数 #include <stdio.h> int main(void) { /*.......*/ return 0; } 其中绿色部分称为main函数。 c语言程序中,main函数是必不可少的。程序运行的时候,会执行main函数的主体部分。 main函数中使用了pri
阅读全文
摘要:1、虽然通过对象式宏来变更元素的数目非常方便,但是每次都需要对程序进行修改,然后重新编译执行。 我们可以定义一个比较大的数组,然后从头开始仅使用其中需要的部分。 #include <stdio.h> #define NUMBER 80 int main(void) { int i, j; int a
阅读全文
摘要:1、 #include <stdio.h> #define NUMBER 4 int main(void) { int i; int a[NUMBER]; int sum = 0; puts("please input the scores."); for (i = 0; i < NUMBER; i
阅读全文

浙公网安备 33010602011771号