Posts

C for loop control using difference not giving the result -

i writing code keep calculating sequence 1+(2/2!)+(3/3!)+..... until difference between 2 subsequent members of sequence 10^-4 subtraction giving me 0.00 , not stopping loop #include<stdio.h> #include<stdlib.h> int main() { int c = 0; double sum = 0; double fact = 1; double seq; double temp = 0; bool check = false; while (check != true) { c++; fact = fact * c; seq = c/fact; if(temp-seq == 1e-04) check = true; // printf("%f\n",temp-seq); temp = seq; } printf("stopped @ %d operations \n",c); system("pause"); return 0; } first of all, read other replies, have info. second, not doing calculations right, se below working example. #include<stdio.h> #include<stdlib.h> #include<stdbool.h> int main() { int count = 0; double sequence = 0; double previous = sequence; double factori...

jquery - javascript .on() function not working -

i have select list, #select1 , when user chooses option list, action happens. tried following javascript code sadly not working: script jquery(document).ready(function(){ $( document ).on( "change", "#select1", function() { alert("test"); }); }); so when choose option, don't test alert. any idea why happening? edit html <select id="select1"> <option selected="selected" disabled="disabled">choose country</option> <option value="2">canada</option> <option value="3">france</option> <option value="4">india</option> <option value="5">poland</option> </select> i think work $('body').on('change','#select1',function(){ alert("test"); }); demo here

layout - Big Cartel Luna Theme. Cart will not proceed to checkout -

i'd love this. on cart page, when "use stores layout" selected, when customers click "check out", keeps cycling on page , won't proceed checkout. known issue luna theme bigcartel. the solution found says need uncheck it, when do, error message: "you must include {{ head_content }} inside <head> tag of content" this means there's no page formatting in code. i'm not big on code, though i've tried bit work, stealing code other pages in theme, , failed. (it's been years since i've messed code, big one). thank you here's code page: <header class="product_header page_header"> <h1>cart</h1> <span class="dash"></span> </header> {% if cart.items != blank %} <form id="cart-form" {% unless cart.shipping.enabled or cart.discount.enabled %}class="no_options"{% endunless %} method="post" action="/cart" ac...

c# - Using .Matches with regex for a char in fluent -

i have class called transaction contains property named source within transaction class have validation using fluentvalidation , trying validate source property using regex i'm having issue //source isnt required when present must 1 character 'x' or 'y' rulefor(transaction => transacion.source) .matches("^(x|y)?$") .when(transaction => transaction.source != null); i getting: error 1 fluentvalidation.irulebuilderinitial<myutility.transaction,char?> not contain definition 'matches' , best extension method overload fluentvalidation.defaultvalidatorextensions.matches<t>(fluentvalidation.irulebuilder<t,string>, system.text.regularexpressions.regex) has invalid arguments i have used exact same code different property no problems, although string not char. there's dot . in code between matches , ("^(x|y)?$") . .rulefor(transaction => transaction....

javascript - Jquery .ajax() local testing -

i've got little .ajax function trying load content after document ready. $(document).ready(function(){ $.ajax({ url: 'php/accounts-blocks.php', cache: false, beforesend: function() { $('#accounts-blocks').html('please wait...'); }, success: function(html) { $('#accounts-blocks').html(html); } }); }); however, when i'm trying test page locally (just on pc), ajax shows "please wait" message forever, , doesn't load content. should install local hosting or in order test ajax functionality, or wrong script? ajax (xhr) not work in browsers (there exceptions such firefox) when running script locally without having local web server installed. chrome example not allow it. use browser less strict security, or install local http server.

uitableview - calling another ViewController on row selection in TableViewController -

Image
i using uitableviewcontroller , on selection of row list want open scene , send info of selected row. got 1 link , followed , attched segue1 segue2 in push mode. when executing throwing error no such segue associated segue1. below code row selection: - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { nslog(@"index %ld",(long)indexpath.row ); [self performseguewithidentifier:@"put_controller" sender:indexpath.self]; } -(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([[segue identifier] isequaltostring:@"put_controller"]) { nsindexpath *indexpath = [self.tableview indexpathforselectedrow]; nsdate *object = _objects[indexpath.row]; [[segue destinationviewcontroller] setdetailitem:object]; } } don't forget set storyboard segue identifier:- put_controller

algorithm - Given an integer z<=10^100, find the smallest row of Pascal's triangle that contains z -

how can find algorithm solve problem using c++: given integer z<=10^100, find smallest row of pascal's triangle contains number z. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 for example if z=6 => result on 4th row. another way describe problem: given integer z<=10^100, find smallest integer n: exist integer k c(k,n) = z. c(k,n) combination of n things taken k @ time without repetition edit solution needs logarithmic time, it's o(log z) . or maybe o( (log z)^2 ) . say looking n,k binomial(n,k)==z given z. each row has largest value in middle, starting n=0 increase row number, n , long middle value smaller given number. actually, 10^100 isn't big, before row 340 find position n0,k0=n0/2 value triangle larger or equal z : binomial(n0,k0)>=z you walk left, i.e. decrease column number k , until find value smaller z . if there matching value in row have hit now. k not large, less 170, step won't executed more , not present perform...