void pows(int n, int i) { if(i == 0) { output(n); } else { --i; arr[i] = 0; pows(n, i); arr[i] = 1; pows(n, i); } }
int main(int argc, char *argv[]) { int n; char iname[512]; char istmt[2048]; int nscanned; n = 0; while(!feof(stdin)) { nscanned = scanf("%s %[^\n]s\n", iname, istmt); if(nscanned == EOF) break; else if(nscanned != 2) { fprintf(stderr, "problem scanning entry %d, scanned %d\n", n, nscanned); exit(1); } name[n] = strdup(iname); stmt[n] = strdup(istmt); n++; printf("name: %s, stmt: %s\n", iname, istmt); } /* n is on to high for an index, but just right as the actual number! */ printf("read %d entries\n", n); pows(n, n); }
void main(int argc, char *argv[]) { int *s = (int*)malloc(sizeof(int)); *s = 0; unsigned char *a = reverse(input(argv[1],s)); char *znak = argv[2]; unsigned char *b = reverse(input(argv[3],s)); unsigned char *c; if(equal(znak,"+")) c = add(a,b); if(equal(znak,"-")) c = sub(a,b); if(equal(znak,"*")) c = mul(a,b); if(equal(znak,"/")) c = deg(a,b); if(equal(znak,"%")) c = mod(a,b); if(equal(znak,"^")) c = pows(a,b); output_file(argv[4],reverse(c)); }
unsigned long long int removes(unsigned long long int a) { unsigned long long int num=0; int d,i=0; while(a!=0) { d=a%10; if(d!=0) { num=num+ pows(i)*d; i++; } a=a/10; } //printf("%llu ",num); return num; }
void GeneratedMesh::buildMesh() { MooseEnum elem_type_enum = getParam<MooseEnum>("elem_type"); if (!isParamValid("elem_type")) { // Switching on MooseEnum switch (_dim) { case 1: elem_type_enum = "EDGE2"; break; case 2: elem_type_enum = "QUAD4"; break; case 3: elem_type_enum = "HEX8"; break; } } ElemType elem_type = Utility::string_to_enum<ElemType>(elem_type_enum); // Switching on MooseEnum switch (_dim) { // The build_XYZ mesh generation functions take an // UnstructuredMesh& as the first argument, hence the dynamic_cast. case 1: MeshTools::Generation::build_line(dynamic_cast<UnstructuredMesh &>(getMesh()), _nx, _xmin, _xmax, elem_type, _gauss_lobatto_grid); break; case 2: MeshTools::Generation::build_square(dynamic_cast<UnstructuredMesh &>(getMesh()), _nx, _ny, _xmin, _xmax, _ymin, _ymax, elem_type, _gauss_lobatto_grid); break; case 3: MeshTools::Generation::build_cube(dynamic_cast<UnstructuredMesh &>(getMesh()), _nx, _ny, _nz, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, elem_type, _gauss_lobatto_grid); break; } // Apply the bias if any exists if (_bias_x != 1.0 || _bias_y != 1.0 || _bias_z != 1.0) { // Reference to the libmesh mesh MeshBase & mesh = getMesh(); // Biases Real bias[3] = {_bias_x, _bias_y, _bias_z}; // "width" of the mesh in each direction Real width[3] = {_xmax - _xmin, _ymax - _ymin, _zmax - _zmin}; // Min mesh extent in each direction. Real mins[3] = {_xmin, _ymin, _zmin}; // Number of elements in each direction. unsigned int nelem[3] = {_nx, _ny, _nz}; // We will need the biases raised to integer powers in each // direction, so let's pre-compute those... std::vector<std::vector<Real>> pows(LIBMESH_DIM); for (unsigned int dir = 0; dir < LIBMESH_DIM; ++dir) { pows[dir].resize(nelem[dir] + 1); for (unsigned int i = 0; i < pows[dir].size(); ++i) pows[dir][i] = std::pow(bias[dir], static_cast<int>(i)); } // Loop over the nodes and move them to the desired location MeshBase::node_iterator node_it = mesh.nodes_begin(); const MeshBase::node_iterator node_end = mesh.nodes_end(); for (; node_it != node_end; ++node_it) { Node & node = **node_it; for (unsigned int dir = 0; dir < LIBMESH_DIM; ++dir) { if (width[dir] != 0. && bias[dir] != 1.) { // Compute the scaled "index" of the current point. This // will either be close to a whole integer or a whole // integer+0.5 for quadratic nodes. Real float_index = (node(dir) - mins[dir]) * nelem[dir] / width[dir]; Real integer_part = 0; Real fractional_part = std::modf(float_index, &integer_part); // Figure out where to move the node... if (std::abs(fractional_part) < TOLERANCE || std::abs(fractional_part - 1.0) < TOLERANCE) { // If the fractional_part ~ 0.0 or 1.0, this is a vertex node, so // we don't need an average. // // Compute the "index" we are at in the current direction. We // round to the nearest integral value to get this instead // of using "integer_part", since that could be off by a // lot (e.g. we want 3.9999 to map to 4.0 instead of 3.0). int index = round(float_index); // Move node to biased location. node(dir) = mins[dir] + width[dir] * (1. - pows[dir][index]) / (1. - pows[dir][nelem[dir]]); } else if (std::abs(fractional_part - 0.5) < TOLERANCE) { // If the fractional_part ~ 0.5, this is a midedge/face // (i.e. quadratic) node. We don't move those with the same // bias as the vertices, instead we put them midway between // their respective vertices. // // Also, since the fractional part is nearly 0.5, we know that // the integer_part will be the index of the vertex to the // left, and integer_part+1 will be the index of the // vertex to the right. node(dir) = mins[dir] + width[dir] * (1. - 0.5 * (pows[dir][integer_part] + pows[dir][integer_part + 1])) / (1. - pows[dir][nelem[dir]]); } else { // We don't yet handle anything higher order than quadratic... mooseError("Unable to bias node at node(", dir, ")=", node(dir)); } } } } } }