Search Results

Search found 6055 results on 243 pages for 'cyclic numbers'.

Page 3/243 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Random numbers from -10 to 10 in C++

    - by Chris_45
    How does one make random numbers in the interval -10 to 10 in C++ ? srand(int(time(0)));//seed for(int i = 0; i < size; i++){ myArray[i] = 1 + rand() % 20 - 10;//this will give from -9 to 10 myArray2[i] =rand() % 20 - 10;//and this will -10 to 9 }

    Read the article

  • Zend Lucene - cannot search numbers

    - by Pavel Dubinin
    Using Zend Lucene I cannot search numbers in description fields Added it like this: $doc->addField(Zend_Search_Lucene_Field::Text('description', $current_item['item_short_description'], 'utf-8')); Googling for this showed that applying following code should solve the problem, but it did not..: Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive()); any thougts?

    Read the article

  • form a number using consecutive numbers

    - by Mahesh
    Hi, I was puzzled with one of the question in Microsoft interview which is as given below: A function should accept a range( 3 - 21 ) and it should print all the consecutive numbers combination's to form each number as given below: 3=1+2 5=2+3 6=1+2+3 7=3+4 9=4+5 10=1+2+3+4 11=5+6 13=6+7 15=1+2+3+4+5 17=7+8 19=8+9 21=10+11 21=1+2+3+4+5+6 could you please help me in forming this sequence in C#? Thanks, Mahesh

    Read the article

  • Formatting numbers in loop

    - by dave9909
    I want to list all numbers from 0000-9999 however I am having trouble holding the zero places. I tried: for(int i = 0; i <= 9999; ++i) { cout << i << "\n"; } but I get: 1,2,3,4..ect How can I make it 0001,0002,0003....0010, etc

    Read the article

  • order array containing text and numbers

    - by ptrn
    I'm looking for the easiest way to sort an array that consists of numbers and text, and a combination of these. E.g. '123asd' '19asd' '12345asd' 'asd123' 'asd12' turns into '19asd' '123asd' '12345asd' 'asd12' 'asd123' This is going to be used in combination with the solution to another question I've asked here. The sorting function in itself works, what I need is a function that can say that that '19asd' is smaller than '123asd'. I'm writing this in JavaScript.

    Read the article

  • Parsing numbers at PreviewTextInput

    - by Nitin Chaudhari
    I have a WPF application in which I have a hook at PreviewTextInput, through that I get the currently entered character and I have the string already entered. Given this I need to write the following function : bool ShouldAccept(char newChar,string existingText) existingText can be comma seperated valid numbers(including exponential) and it should just return false when invalid characters are pressed. My code(if else based) currently has a lot of flaws, I wanted to know if there is any smart way to do it.

    Read the article

  • SQL, Auxiliary table of numbers

    - by vzczc
    For certain types of sql queries, an auxiliary table of numbers can be very useful. It may be created as a table with as many rows as you need for a particular task or as a user defined function that returns the number of rows required in each query. What is the optimal way to create such a function?

    Read the article

  • Pi/Infinite Numbers

    - by Ben Shelock
    I'm curious about infinite numbers in computing, in particular pi. For a computer to render a circle it would have to understand pi. But how can it if it is infinite? Am I looking too much into this? Would it just use a rounded value?

    Read the article

  • C code to round numbers

    - by webgenius
    Is there any way to round numbers in C? I do not want to use ceil and floor. Is there any other alternative? I came across this code snippet when I Googled for the answer: (int)(num < 0 ? (num - 0.5) : (num + 0.5)) The above line always prints the value as 4 even when float num =4.9. Please suggest a solution.

    Read the article

  • How do find the longest path in a cyclic Graph between two nodes?

    - by Nazgulled
    Hi, I already solved most the questions posted here, all but the longest path one. I've read the Wikipedia article about longest paths and it seems any easy problem if the graph was acyclic, which mine is not. How do I solve the problem then? Brute force, by checking all possible paths? How do I even begin to do that? I know it's going to take A LOT on a Graph with ~18000. But I just want to develop it anyway, cause it's required for the project and I'll just test it and show it to the instructor on a smaller scale graph where the execution time is just a second or two. At least I did all tasks required and I have a running proof of concept that it works but there's no better way on cyclic graphs. But I don't have clue where to start checking all these paths...

    Read the article

  • Algorithm to generate N random numbers between A and B which sum up to X

    - by Shaamaan
    This problem seemed like something which should be solvable with but a few lines of code. Unfortunately, once I actually started to write the thing, I've realized it's not as simple as it sounds. What I need is a set of X random numbers, each of which is between A and B and they all add up to X. The exact variables for the problem I'm facing seem to be even simpler: I need 5 numbers, between -1 and 1 (note: these are decimal numbers), which add up to 1. My initial "few lines of code, should be easy" approach was to randomize 4 numbers between -1 and 1 (which is simple enough), and then make the last one 1-(sum of previous numbers). This quickly proved wrong, as the last number could just as well be larger than 1 or smaller than -1. What would be the best way to approach this problem? PS. Just for reference: I'm using C#, but I don't think it matters. I'm actually having trouble creating a good enough solution for the problem in my head.

    Read the article

  • 3 threads printing numbers of different range

    - by user875036
    This question was asked in an Electronic Arts interview: There are 3 threads. The first thread prints the numbers 1 to 10. The second thread prints the numbers 11 to 20. The third thread prints the numbers from from 21 to 30. Now, all three threads are running. The numbers are printed in an irregular order like 1, 11, 2, 21, 12 etc. If I want numbers to be printed in sorted order like 1, 2, 3, 4..., what should I do with these threads?

    Read the article

  • Prolog: find all numbers of unique digits that can be formed from a list of digits

    - by animo
    The best thing I could come up with so far is this function: numberFromList([X], X) :- digit(X), !. numberFromList(List, N) :- member(X, List), delete(List, X, LX), numberFromList(LX, NX), N is NX * 10 + X. where digit/1 is a function verifying if an atom is a decimal digit. The numberFromList(List, N) finds all the numbers that can be formed with all digits from List. E.g. [2, 3] -> 23, 32. but I want to get this result: [2, 3] -> 2, 3, 23, 32 I spent a lot of hours thinking about this and I suspect you might use something like append(L, _, List) at some point to get lists of lesser length. I would appreciate any contribution.

    Read the article

  • Smarty multiple random numbers list

    - by Heinrich
    Hey Stackoverflow-Folks, is there any smart way to post random numbers (e.g. 1-4) in a list by using the smarty tpl-engine? standart list sorted 1-5: <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> Here's my solution (PHP): <ul> {foreach from=randomNumbers} <li>{smarty.randomNumbers}</li> {/foreach} </ul> modified list sorted 1-5 (random): <ul> <li>3</li> <li>2</li> <li>5</li> <li>1</li> <li>4</li> </ul> I've really tested nearly everything, but I do only need a smart & small solution for this :-) Kind Regards, Heinrich

    Read the article

  • Prime Numbers Code Help

    - by andrew
    Hello Everybody, I am suppose to "write a Java program that reads a positive integer n from standard input, then prints out the first n prime number." It's divided into 3 parts. 1st: This function will return true or false according to whether m is prime or composite. The array argument P will contain a sufficient number of primes to do the testing. Specifically, at the time isPrime() is called, array P must contain (at least) all primes p in the range 2 p m . For instance, to test m = 53 for primality, one must do successive trial divisions by 2, 3, 5, and 7. We go no further since 11 53 . Thus a precondition for the function call isPrime(53, P) is that P[0] = 2 , P[1] = 3 , P[2] = 5, and P[3] = 7 . The return value in this case would be true since all these divisions fail. Similarly to test m =143 , one must do trial divisions by 2, 3, 5, 7, and 11 (since 13 143 ). The precondition for the function call isPrime(143, P) is therefore P[0] = 2 , P[1] = 3 , P[2] = 5, P[3] = 7 , and P[4] =11. The return value in this case would be false since 11 divides 143. Function isPrime() should contain a loop that steps through array P, doing trial divisions. This loop should terminate when 2 either a trial division succeeds, in which case false is returned, or until the next prime in P is greater than m , in which case true is returned. Then there is the "main function" • Check that the user supplied exactly one command line argument which can be interpreted as a positive integer n. If the command line argument is not a single positive integer, your program will print a usage message as specified in the examples below, then exit. • Allocate array Primes[] of length n and initialize Primes[0] = 2 . • Enter a loop which will discover subsequent primes and store them as Primes[1] , Primes[2], Primes[3] , ……, Primes[n -1] . This loop should contain an inner loop which walks through successive integers and tests them for primality by calling function isPrime() with appropriate arguments. • Print the contents of array Primes[] to stdout, 10 to a line separated by single spaces. In other words Primes[0] through Primes[9] will go on line 1, Primes[10] though Primes[19] will go on line 2, and so on. Note that if n is not a multiple of 10, then the last line of output will contain fewer than 10 primes. The last function is called "usage" which I am not sure how to execute this! Your program will include a function called Usage() having signature static void Usage() that prints this message to stderr, then exits. Thus your program will contain three functions in all: main(), isPrime(), and Usage(). Each should be preceded by a comment block giving it’s name, a short description of it’s operation, and any necessary preconditions (such as those for isPrime().) And hear is my code, but I am having a bit of a problem and could you guys help me fix it? If I enter the number "5" it gives me the prime numbers which are "6,7,8,9" which doesn't make much sense. import java.util.; import java.io.; import java.lang.*; public class PrimeNumber { static boolean isPrime(int m, int[] P){ int squarert = Math.round( (float)Math.sqrt(m) ); int i = 2; boolean ans=false; while ((i<=squarert) & (ans==false)) { int c= P[i]; if (m%c==0) ans= true; else ans= false; i++; } /* if(ans ==true) ans=false; else ans=true; return ans; } ///****main public static void main(String[] args ) { Scanner in= new Scanner(System.in); int input= in.nextInt(); int i, j; int squarert; boolean ans = false; int userNum; int remander = 0; System.out.println("input: " + input); int[] prime = new int[input]; prime[0]= 2; for(i=1; i ans = isPrime(j,prime); j++;} prime[i] = j; } //prnt prime System.out.println("The first " + input + " prime number(s) are: "); for(int r=0; r }//end of main } Thanks for the help

    Read the article

  • Factory Method and Cyclic Dependancy

    - by metdos
    If I'm not wrong, because of its nature in factory method there is cyclic dependency: Base class needs to know subclasses because it creates them, and subclasses need to know base class. Having cyclic dependency is bad programming practice, is not it? Practically I implemented a factory, I have problem above, even I added #ifndef MYCLASS_H #define MYCLASS_H #endif I'm still getting Compiler Error C2504 'class' : base class undefined And this error disappers when I remove subclass include from base class header.

    Read the article

  • Problems in "Save as PDF" plugin with Arabic numbers

    - by Mohamed Mohsen
    I use the "Save as PDF" plugin with Word 2007 to generate a PDF document from a DOCX document. It works great except that the Arabic numbers in the Word file have been converted to English numbers in the PDF document. Kindly find two links containing two screen shots explaining the problem. The first image is the generated PDF file with the English numbers highlighted. The second image is the original word file with the Arabic numbers highlighted. Update: Thanks very much Isaac, ChrisF and Wil. I changed the Numeral at word to Context and confirmed that all the numbers are Arabic at the Word file. I still have the problem as the PDF file still have English numbers. (Note: The Arabic numbers called Hindi numbers). I also tried changing the font to Tahoma with no hope.

    Read the article

  • Pseudo random numbers in php

    - by pg
    I have a function that outputs items in a different order depending on a random number. for example 1/2 of the time Popeye's and its will be #1 on the list and Taco Bell and its logo will be #2 and half the time the it will be the other way around. The problem is that when a user reloads or comes back to the page, the order is re-randomized. $Range here is the number of items in the db, so it's using a random number between 1 and the $range. $random = mt_rand(1,$range); for ($i = 0 ; $i < count($variants); $i++) { $random -= $variants[$i]['weight']; if ($random <= 0) { $chosenoffers[$tag] = $variants[$i]; break; } } I went to the beginning of the session and set this: if (!isset($_SESSION['rannum'])){ $_SESSION['rannum']=rand(1,100); } With the idea that I could replace the mt_rand in the function with some sort of pseudo random generator that used the same 1-100 random number as a seed throughout the session. That way i won't have to rewrite all the code that was already written. Am I barking up the wrong tree or is this a good idea?

    Read the article

  • C: Random Number Generation - What (If Anything) Is Wrong With This

    - by raoulcousins
    For a simple simulation in C, I need to generate exponential random variables. I remember reading somewhere (but I can't find it now, and I don't remember why) that using the rand() function to generate random integers in a fixed range would generate non-uniformly distributed integers. Because of this, I'm wondering if this code might have a similar problem: //generate u ~ U[0,1] u = ( (double)rand() / ((double)(RAND_MAX)); //inverse of exponential CDF to get exponential random variable expon = -log(1-u) * mean; Thank you!

    Read the article

  • VB.net Need Text Box to Only Accept Numbers

    - by Rico Jackson
    I'm fairly new to VB.net (self taught) and was just wondering if someone out there could help me out with some code. I'm not trying to do anything to invovled, just have a textbox that takes numeric value from 1 to 10. I don't want it to take a string or any number above 10. If some types a word or character an error message will appear, telling them to enter a valid number. This is what I have, obviously it's not great as I am having problems. Thanks again to anyone who can help. If TxtBox.Text > 10 Then MessageBox.Show("Please Enter a Number from 1 to 10") TxtBox.Focus() ElseIf TxtBox.Text < 10 Then MessageBox.Show("Thank You, your rating was " & TxtBox.Text) Total = Total + 1 ElseIf IsNumeric(TxtBox.Text) Then MessageBox.Show("Thank you, your rating was " & ValueTxtBox.Text) End If ValueTxtBox.Clear() ValueTxtBox.Focus()

    Read the article

  • Help with float numbers in Java

    - by Alvin
    Hi, Could anyone please me why the output of the following programme is not " different different"? public static void main(String[] args) { float f1=3.2f; float f2=6.5f; if(f1==3.2) System.out.println("same"); else System.out.println("different"); if(f2==6.5) System.out.println("same"); else System.out.println("different"); } o/p :different same

    Read the article

  • Eclipse Subversive revision numbers on multiple project commit

    - by CannyDuck
    If I have 2 projects in Eclipse that refers to the same repository location. repository location: svn://server project-module1 - svn://server/trunk/project-module1 project-module2 - svn://server/trunk/project-module2 So if I sync the project change with Subversive and have a change in module1 and module2 that refers to the same context I select all files and perform one commit, but if I look into my project revisions after that I see that 2 revisions were created. One for module1 and one for module2 with the same comment. How can I change the behave that only one revision number is created?

    Read the article

  • php numbers: assert( 1.0 < 2.0 )

    - by xtofl
    How can this <?php assert( 1.0 < 2.0 ); ?> result in Warning: assert() [function.assert]: Assertion failed in C:\Program Files (x86)\wamp\www\test.php on line 2 Edit: depending on the file I put this code in, 1.0 < 2.0 evaluates to false or true.

    Read the article

  • Get 100 highest numbers from an infinite list

    - by Sachin Shanbhag
    One of my friend was asked this interview question - "There is a constant flow of numbers coming in from some infinite list of numbers out of which you need to maintain a datastructure as to return the top 100 highest numbers at any given point of time. Assume all the numbers are whole numbers only." This is simple, you need to keep a sorted list in descending order and keep a track on lowest number in that list. If new number obtained is greater than that lowest number then you have to remove that lowest number and insert the new number in sorted list as required. Then question was extended - "Can you make sure that the Order for insertion should be O(1)? Is it possible?" As far as I knew, even if you add a new number to list and sort it again using any sort algorithm, it would by best be O(logn) for quicksort (I think). So my friend told it was not possible. But he was not convinced, he asked to maintain any other data structure rather than a list. I thought of balanced Binary tree, but even there you will not get the insertion with order of 1. So the same question I have too now. Wanted to know if there is any such data structure which can do insertion in Order of 1 for above problem or it is not possible at all.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >