#include<stdio.h>
#include<conio.h>
int main()
{
int ar1[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
int ar2[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int ar3[3][3];
int i,j,k;
for(i=0;i<3;i++)
{
ar3[i][j] = 0;
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
ar3[i][j] = ar3[i][j]+(ar1[i][k]*ar2[k][j]);
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++);
printf("%d\t",ar3[i][j]);
}
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我在Dev C++中编译代码时,它没有给出任何错误但是无法运行并且应用程序停止工作.它出什么问题了?
当我尝试移动合法的图块(即与'空白'图块0相邻的图块)时,没有任何反应.如果磁贴是非法的,程序将按预期运行.这是移动功能:
bool move(int tile)
{
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == tile)
{
// stops program from going out of bounds
if (j < d)
{
if (board[i][j + 1] == 0)
{
swap(board[i][j], board[i][j + 1]);
return true;
}
}
if (j > 0)
{
if (board[i][j - 1] == 0)
{
swap(board[i][j], board[i][j - 1]);
return true;
}
}
if (i …Run Code Online (Sandbox Code Playgroud) 我试图简单地创建一个返回2D数组的方法,该数组具有基于给定模式输入的所有值.Eclipse说我的代码没有任何错误,但是当我去运行时,我得到了响应"[[I @ 2a139a55".我用Google搜索并了解它是什么,但我仍然不知道如何修复我的代码.
public class Transpose {
public static int[][] createPatterned2DArray(int row,int column){
int width = column;
int height = row;
int[][] array = new int[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
array[i][j] = i + j + (width * i);
}
}
return array;
}
public static void main(String[] args) {
System.out.print(createPatterned2DArray(3,5));
}
}
Run Code Online (Sandbox Code Playgroud) 我有这个数组:
array = [["R.M", 20], ["R.U-CS", 3], ["R.M-TIC", 3], ["R.J.CONF", 20]]
Run Code Online (Sandbox Code Playgroud)
我想要sum数值,所以我使用以下方法将其转换为单个数组flatten:
array = array.flatten
#=> ["R.M", 20, "R.U-CS", 3, "R.M-TIC", 3, "R.J.CONF", 20]
Run Code Online (Sandbox Code Playgroud)
然后:
a = []
array.each do |r|
a << r if r.class == Fixnum
end
a
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我正在寻找一个更简单的解决方案,可能首先将数组转换为"唯一numeric"数组:
[20, 3, 3, 20]
Run Code Online (Sandbox Code Playgroud) var_dump($ib); 给我以下输出:
array (
'data' => array (
0 => array (
'id' => '2015469353355_151',
'from' => array (
'name' => 'Aah',
'id' => '100000292544713',
),
'message' => 'zzzz',
'created_time' => '2012-06-08T06:16:41+0000',
),
1 => array (
'id' => '2015469353355_152',
'from' => array (
'name' => 'assaaaa',
'id' => '100000292544713',
),
'message' => 'zzzz',
'created_time' => '2012-06-08T06:16:51+0000',
),
),
'paging' => array (
'previous' => 'https://graph.facebook.com/2015469353355/comments?limit=25&value=1&redirect=1&__paging_token=2015469353355_175&access_token=AAAFfJS6rRAABAHKGZCy57ZCrSEdQL2kUIYqZAcNBLkbnKTBxRhhx9CTvnUlq2LcAK1kZBWnV6AH5RpvkmGYRFzvk12kNXLe6OhjjapH5PEIUwv1h2tYl&since=1340009948&__previous=1',
'next' => 'https://graph.facebook.com/2015469353355/comments?limit=25&value=1&redirect=1&access_token=AAAFfJS6rRAABAHKGZCy57ZCrSEdQL2kUIYqZAcNBLkbnKTBxRhhx9CTvnUlq2LcAK1kZBWnV6AH5RpvkmGYRFzvk12kNXLe6OhjjapH5PEIUwv1h2tYl&until=1340009948&__paging_token=2015469353355_175',
),
)
Run Code Online (Sandbox Code Playgroud)
如何检索'next'的值?
有没有办法在Perl中创建/模拟3D(或更高维度)数组?
我试图在网上搜索,但一无所获.
我的功能被注释掉了因为我试图首先解决这个问题> <.但是当我尝试将数组传递给函数时,编译会出现错误消息.
error: cannot convert ‘char*’ to ‘char (*)[7][49]’ for argument ‘1’ to
‘void save(char (*)[7][49])’
Run Code Online (Sandbox Code Playgroud)
这发生在我的代码中的第63:61,67:46和70:36行.
//Header
#include <iostream>
#include <fstream>
using namespace std;
//function prototype
/*
Name: deal
Process: takes cards from file into 3d array and 2d array
Input: array name (int),2d array name (int)
Output: none
Dependencies: none
*/
void deal ( char tablue [7][7][49] , char wastePile [24][24]);
/*
Name: displayCards
Process: Displays cards from array to screen
Input: tablue array (char)
Output to screen: …Run Code Online (Sandbox Code Playgroud) 我是C编程的新手,我需要使用2D整数数组(矩阵).例如,我这样做:
void main(){
int matrix[2][2] = { {0,1}, {2,3} };
printf("%i", matrix[4][4]); /*Here should be an index error, but that doesn't happen*/
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
大家早,
我目前有一个数组$文件,当我运行时:
print_r($files);
Run Code Online (Sandbox Code Playgroud)
输出是:
Array ( [0] => 62007-00-15.pdf [1] => 62007-15.pdf [2] => 62007-15SW.pdf [3] => 85080-00.pdf )
Run Code Online (Sandbox Code Playgroud)
我希望使用 - 作为分隔符数组对此进行字符串拆分,因此它仍然存储在单个数组中,但有3个部分.我使用以下代码:
// STRING SPLIT FILENAME ARRAY
foreach($files as $key => $value) {
$stringsplit = explode('-', $key);
$new_array[] = array(
'FPN1' => $stringsplit[0],
'FPN2' => $stringsplit[1],
'FDW' => $stringsplit[2]
);
}
Run Code Online (Sandbox Code Playgroud)
但我得到以下结果:
Array ( [0] => Array ( [FPN1] => 0 [FPN2] => [FDW] => ) [1] => Array ( [FPN1] => 1 [FPN2] => [FDW] => ) [2] => …Run Code Online (Sandbox Code Playgroud) 我有2个PHP数组,看起来像这样..
$array1
--------
Array
(
[0] => Array
(
[0] => 64
[1] => Apple
)
[1] => Array
(
[0] => 22
[1] => Pear
)
[2] => Array
(
[0] => 3
[1] => Raisin
)
[3] => Array
(
[0] => 15
[1] => Grape
)
[4] => Array
(
[0] => 11
[1] => Banana
)
[5] => Array
(
[0] => 4
[1] => Orange
)
)
$array2
--------
Array
(
[0] => Array
( …Run Code Online (Sandbox Code Playgroud)