int NumberOf1Between1AndN_Solution(int n) { if (n == 0) return 0; int result = n / 10; if (result * 10 < n) result++; int i = 1; while (n > maxnum(i)){ int large = powerof(10, i + 1); int small = powerof(10, i); int left = n / large; result += left * small; if (left * large + small <= n){ int view; if (n < left * large + 2 * small) view = (n % small) + 1; else view = small; result += view; } i++; } return result; }
int ast_register_translator(struct ast_translator *t) { char tmp[80]; t->srcfmt = powerof(t->srcfmt); t->dstfmt = powerof(t->dstfmt); if (t->srcfmt >= MAX_FORMAT) { ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt)); return -1; } if (t->dstfmt >= MAX_FORMAT) { ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt)); return -1; } calc_cost(t,1); if (option_verbose > 1) ast_verbose(VERBOSE_PREFIX_2 "Registered translator '%s' from format %s to %s, cost %d\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost); ast_mutex_lock(&list_lock); if (!added_cli) { ast_cli_register(&show_trans); added_cli++; } t->next = list; list = t; rebuild_matrix(0); ast_mutex_unlock(&list_lock); return 0; }
/*! Build a set of translators based upon the given source and destination formats */ struct ast_trans_pvt *ast_translator_build_path(int dest, int source) { struct ast_trans_pvt *tmpr = NULL, *tmp = NULL; source = powerof(source); dest = powerof(dest); while(source != dest) { if (!tr_matrix[source][dest].step) { /* We shouldn't have allocated any memory */ ast_log(LOG_WARNING, "No translator path from %s to %s\n", ast_getformatname(source), ast_getformatname(dest)); return NULL; } if (tmp) { tmp->next = malloc(sizeof(*tmp)); tmp = tmp->next; } else tmp = malloc(sizeof(*tmp)); if (!tmp) { ast_log(LOG_WARNING, "Out of memory\n"); if (tmpr) ast_translator_free_path(tmpr); return NULL; } /* Set the root, if it doesn't exist yet... */ if (!tmpr) tmpr = tmp; tmp->next = NULL; tmp->nextin = tmp->nextout = ast_tv(0, 0); tmp->step = tr_matrix[source][dest].step; tmp->state = tmp->step->newpvt(); if (!tmp->state) { ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest); ast_translator_free_path(tmpr); return NULL; } /* Keep going if this isn't the final destination */ source = tmp->step->dstfmt; } return tmpr; }
int maxnum(int n) { int result = 0; if (n > 0){ for (int i = 0; i < n; ++i) result += 9 * powerof(10, i); } return result; }
unsigned int powerof(unsigned int user_number,unsigned int a) { if(a<=0){return 1;} else { answer=user_number*powerof(user_number,a-1); return answer; } }
int main () { int const a = 2; int const b = 4; int x = powerof(a, b); float y = 3.1415; std::cout << a << "^" << b << " = " << x << ";\n"; if (y == 3.1415) std::cout << y << " is equal to 3.1415!\n"; else std::cout << y << " is not equal to 3.1415!\n"; }
void main() { unsigned int user_number; unsigned int a; unsigned int ans; printf("Please enter your number here\r\n"); scanf("%d",&user_number); printf("how big do you want the power to be?\r\n"); scanf("%d",&a); ans = powerof(user_number,a); printf("\n %d to the power of %d = %d\r\n",user_number,a,ans); }
int main() { int x = 10; int y = 3; int res = powerof(x, y); std::cout << x << " upphöjt till " << y << " är " << res << std::endl; float z = 0.29; int w = (int) (z * x * x); if (z * x * x == 29) std::cout << z << "*" << x * x << " är 29" << std::endl; else std::cout << z << "*" << x * x << " är inte 29" << std::endl; }