#include <iostream>
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>
#include <math.h>
using namespace std;
void display(void) {
float cx = 200, cy = 200, rad = 50;
float startx = cx - rad;
float starty = cy;
int x = startx, y = starty;
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
glVertex2f((x - 250.f) / 250.f, (250.f - y) / 250.f);
while (x < cx + rad) {
x++;
y = cy - sqrt(rad * rad - (x - cx) * (x - cx)); …Run Code Online (Sandbox Code Playgroud) 我是opencl domian的新手.我已阅读了一些书籍并尝试编译以下代码
#define __CL_ENABLE_EXCEPTIONS
#define __NO_STD_VECTOR
#define PROGRAM_FILE "blank.cl"
#define KERNEL_FUNC "blank"
//#define __MAX_DEFAULT_VECTOR_SIZE 100
#include <cstdio>
#include <fstream>
#include <iostream>
#include <iterator>
#ifdef Windows
#include <OpenCL/cl.hpp>
#else
#include <CL/cl.hpp>
#endif
using namespace std;
using namespace cl;
int main() {
// int n = 10;
vector<Platform> platforms;
vector<Device> devices;
try {
} catch (exception e) {
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但它给了我很多错误.
其中大多数如下
Error 14 error C4996: 'cl::vector<char *,10>': was declared deprecated C:\Program Files (x86)\AMD APP SDK\2.9\include\CL\cl.hpp 1138 1 Matrix_multilpy_C
Run Code Online (Sandbox Code Playgroud)
那么任何人都可以帮助我.我使用visual …
我试图在c中创建一个程序来解决数独游戏,其中我试图在无符号长整数变量中存储一个等于2*3*5*7*11*13*17*19*23*29的数字.在32位Ubuntu机器上使用boath gcc和g ++进行编译时,我收到整数溢出错误.
请帮我存储和使用这个号码,或建议替代方案.
我将整个代码包括在内以供参考.
#include <stdio.h>
#include <stdlib.h>
int main() {
int sudoku[9][9] = {2, 8, 0, 0, 0, 3, 0, 0, 0, // 0 is used to denote blank
4, 7, 0, 0, 8, 6, 0, 9, 1, 0, 0, 5, 0, 9, 0, 2, 3, 0,
0, 9, 0, 5, 2, 0, 4, 8, 6, 5, 0, 0, 0, 0, 0, 0, 0, 3,
8, 6, 1, 0, 7, 4, 0, 5, 0, 0, 3, 4, 0, …Run Code Online (Sandbox Code Playgroud) char choice, y, n;
float percentage;
int marks;
printf("Do you want to know your percentage?(y/n):\n\n");
scanf(" %c", &choice);
if (choice == 'y') {
printf("Enter Your 2nd Sem Marks:\n\n");
scanf(" %d", &marks);
percentage = (marks / 775) * 100;
printf("Your 2nd Sem Percentage is %.2f", percentage);
} else
printf("Thankyou!!!!\n\n\n");
Run Code Online (Sandbox Code Playgroud)
我无法使用上面的代码计算百分比 - 我输出0.00 ...
例如,当我输入为536而不是显示结果为69.16时,它显示0.00请帮助我
我有一个向量填充自定义类型的值,并且find()算法抱怨它无法为值比较找到合适的==运算符.我已经实现了这样:
bool Ship::operator==(const Ship& source) {
return (_type == source._type &&
_damagedSquares == source._damagedSquares &&
_orientation == source._orientation && _state == source._state);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试了"朋友"方法,但这也不起作用.类本身的结构如下:
class Ship {
private:
ShipType _type;
int _damagedSquares;
ShipOrientation _orientation;
ShipState _state;
public:
Ship();
Ship(ShipType type);
~Ship();
bool operator==(const Ship& source);
};
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
附加信息:
std::vector<Ship> remainingShips;
MultiArray& squares = opponentGridCopy.GetSquares();
for (RowIterator rowIterator = squares.begin(); rowIterator != squares.end();
++rowIterator) {
for (ColumnIterator columnIterator = rowIterator->begin();
columnIterator != rowIterator->end(); ++columnIterator) {
Square* current = &(*columnIterator);
SquareState currentState …Run Code Online (Sandbox Code Playgroud) #include <iostream>
using namespace std;
class armon {
int a;
int b;
public:
armon(int newA, int newB) : a(newA), b(newB) {}
armon setA(int newA) {
a = newA;
return *this;
}
armon setB(int newB) {
b = newB;
return *this;
}
void print(void) { cout << a << endl << b; }
};
int main() {
armon s(3, 5);
s.setA(8).setB(9);
s.print();
}
Run Code Online (Sandbox Code Playgroud)
嗨,大家好我最近学习了递归,我尝试了很多返回类型,似乎我在过去的一两天里一直在努力解决这个问题.可悲的是,我没有运气.
这个想法是:
码:
string convert(int value, int b){
stringstream s;
//Once the value is 0 or 1 it returns the whole result
if(value ==0 || value ==1)
return s.str();
else
{
//I store the remainder results in the stringstream and call the function again
s<<convert(value/b,b)<<value%b;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个函数,可以在向量中找到所有多个元素.如果我发送{1,2,3,4,5,1,2,3,3,7}它返回{1,2,3}.我的输入向量有大约100到10000个元素,但我希望只有很少的不同(!)重复; 约1-5%.
因此,如果我已经多次识别出一个元素,我会检查我的重复矢量.如果是,则该函数将继续执行下一个元素(如果有).为此我用了一个goto.
但是我需要在之后有一个命令goto label.否则编译器会抱怨.有没有办法避免这个并保持goto?我知道我可以使用其他方法,例如相应地设置bool并使用if().不过我认为goto方法很简单.
vector<int> findDublicates(vector<int> const& v) {
// e.g. {1,2,3,4,5,1,2,3,7} -> {1,2,3}
vector<int> dublicates;
for (auto it(v.begin()); it != v.end() - 1;
++it) { // go through each element except the last
for (auto const& i :
dublicates) { // check if this is already a known dublicate
if (i == *it)
goto nextElement; // if so, goto the next element in v
}
for (auto it2(it + 1); …Run Code Online (Sandbox Code Playgroud)