package hanqi; import java.util.Scanner; public class Test7 { public static void main(String[] args) { //在主方法中定义一个大小为50的一维整型数组,数组i名为x,数组中存放着{1,3,5,…,99}输出这个数组中的所有元素,每输出十个换一行 int [] x=new int[50]; int a =1; for(int i=0;i<50;i++) { x[i]=a; a+=2; } for(
import edu.princeton.cs.algs4.*; public class No_1_1_13 { public static void main(String[] args) { int m=4; int n=3; int [][] a = new int[m][n]; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { a[i][j]=i+j; StdOut.print(a[i][j]); } StdOut.println(); }
13.10 Write a function in C called my2DAlloc which allocates a two-dimensional array. Minimize the number of calls to malloc and make sure that the memory is accessible by the notation arr[i][j]. 这道题让我们写个C语言函数my2DAlloc用来给一个二维数组分配内存,并且让我们尽可能的少调用malloc
//编写一个函数:tt指向一个M行N列的二维数组,求出二维数组每列中最小的元素,并依次放入pp所指的一维数组中.二维数组中的数在主函数中赋予. //重难点:求出的是每一列的最小值,这里要注意,学会简化代码,省去一些多余定义的变量. #include <stdio.h> #define M 3 #define N 4 void fun ( int tt[M][N], int pp[N] ) { //简化代码 int i, j;//不定义变量n,使用i即可.不定义min直接赋值给pp即可. ; i