嗨,我想学习在C中使用MPI.我在Windows 7上使用Codeblocks
我运行这个程序:
#include <stdio.h>
#include <mpi.h>
void main (int argc, char *argv[]) {
int err;
err = MPI_Init(&argc, &argv);
printf("Hello world!\n");
err = MPI_Finalize();
}
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我在"mpi.h"收到错误.有没有办法添加库?
我试图使用以下命令将矩阵分解为列向量:
z = data(:, 3);
Run Code Online (Sandbox Code Playgroud)
但是,我继续收到错误"不平衡或意外的括号或括号"
我的矩阵数据如下所示:
column1 column2 column3
'Color' 'Size' 'Length'
'blue' 'medium' 21.5
'green' 'large' 30
'gray' 'small' 31
[...] [...] [...] more values.
Run Code Online (Sandbox Code Playgroud)
如何将这一个矩阵分成3个不同的列(x,y,z)?
我有以下字符日期格式:
"3/1990"
"4/1990"
"5/1990"
...
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码:
data work.temps;
set indata;
newdate = input(strip(Date), MMYYSw.);
rename newdate = date;
run;
Run Code Online (Sandbox Code Playgroud)
我继续收到以下错误消息: Informat MMYYSW was not found or could not be loaded.
我试图计算 3 * 3 矩阵(或更多)的行列式,矩阵值范围从 (-1, 到 1)。然而,当我计算行列式时,我得到的结果是0。
[...]
srand(time(NULL));
//Random generation of values between -1 and 1
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
temp = (rand() % (500)) + 0;
temp = temp/250;
array[i][j] = (temp - 1);
}
Run Code Online (Sandbox Code Playgroud)
[...]
double array2[10][10];
double detrm = 0;
int s = 1;
int i, j, m, n, c;
for (c = 0; c < x; c++)
{
m = 0;
n …Run Code Online (Sandbox Code Playgroud) 我想使用函数re.findall(),它在网页中搜索某个模式:
from urllib.request import Request, urlopen
import re
url = Request('http://www.cmegroup.com/trading/products/#sortField=oi&sortAsc=false&venues=3&page=1&cleared=1&group=1', headers={'User-Agent': 'Mozilla/20.0.1'})
webpage = urlopen(url).read()
findrows = re.compile('<td class="cmeTableCenter">(.*)</td>')
row_array = re.findall(findrows, webpage) #ERROR HERE
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
TypeError: can't use a string pattern on a bytes-like object
Run Code Online (Sandbox Code Playgroud) 我创建了一个链表,当我尝试打印节点的值并使用NULL作为绑定时,它不起作用.例如:
#include <iostream>
typedef struct Node;
typedef Node* Node_ptr;
struct Node
{
int i;
Node_ptr next;
};
int main()
{
Node_ptr ptr, head;
ptr = new Node;
head = ptr;
// load
for(int j = 0; j < 4; j++)
{
ptr->next = new Node;
ptr->i = j;
ptr = ptr->next;
}
// print
ptr = head;
while(ptr->next != NULL)
{
std::cout << "print: " << ptr->i << std::endl;
ptr = ptr->next;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,代码会陷入while循环中的无限循环中.它永远不会理解链表只有5个节点长,它只是继续前进.我不明白为什么会这样.
我想知道静态是如何工作的.这是一个例子:
void count()
{
static int x = 1;
cout << "Static: " << x << endl;
x++;
return;
}
int main()
{
//Static variable test
cout << endl;
count();
count();
}
Run Code Online (Sandbox Code Playgroud)
该程序输出"1和2".但我想知道第二次调用函数"count"时,为什么不执行"static int x = 1"行?
是不是建议以这种方式转换字符串:
string input = "81.312";
double val = atof(input.c_str());
Run Code Online (Sandbox Code Playgroud) 我试图为回文实现一个解决方案,我认为我的逻辑是正确的,但我的程序陷入了无限循环,我收到"Prep.exe已停止工作"的错误消息
int main()
{
string word, reverse;
cout << "Please enter a word to test for palindrome : ";
cin >> word;
cout << "Your word is: "<< word << endl;
int i = 0;
int size = word.length() - 1;
while (size >= 0)
{
reverse[i++] = word[size--];
//cout << reverse[i++];
}
cout << "The reversed word is: " << reverse << endl;
if (word == reverse)
cout << "It is palindrome" << endl;
else
cout << "It is …Run Code Online (Sandbox Code Playgroud) 我创建了一个结构:
struct time
{
int hours;
int minutes;
int seconds;
double total_time;
double price;
time* next;
time* back;
};
Run Code Online (Sandbox Code Playgroud)
我已经创建了2个指向结构的指针:
time* traverse, head;
Run Code Online (Sandbox Code Playgroud)
我想将头部的位置指向与头部相同的位置:
traverse = new time;
head = traverse; // Error here
Run Code Online (Sandbox Code Playgroud)
为什么我在作业中收到错误?