- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 2
- Posts with Upvotes
- 2
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
I am an old man who is interested in, among other things, computer programming and mathematical applications of computers in particular.
- Interests
- Music, astronomy
- PC Specs
- GATEWAY WITH amd ATHLON cpu, WINDOWS 98
39 Posted Topics
Re: [QUOTE=Narue]If it's a square matrix then you can do it with something like this: [code] for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { int save = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = save; } } [/code] … | |
Re: I've been following this thread and I also downloaded the Bloodshed compiler. Can you tell me where that online tutorial is? | |
Re: [QUOTE=nsavvinv]Hi everybody, is there a simple way to print a floating point number in its internal representation (i.e. binary or hex) in C(C++)? Yet another question -- is there a linux utility to do the opposite thing with a binary file (i.e. choose a range of bits and convert it … | |
A rather old C++ book I have says that one class may be declared a friend class of a second, and then the first class can access the private data of the second. I tried this example [code] #include <iostream.h> class secret { friend class not; private : int a; … | |
Re: [QUOTE=mus_203]Hi I have a little question which I have partly tried but I am not completely sure if I am doing it correctly. Heres the question Does the equation 2x=26(mod32) have any solutions? If it does determine them and if not then explain why. Down below is how I approached … | |
Re: Here's my contribution, on the attached file. I hope iit's of some use to you | |
Re: Someone commented that to see if n is a prime you only have to check possible divisors < sqrt(n). In addition, you can decrease the computing time a lot by testing the divisor 2 , then 3, 5, 7..., skipping every other integer. The reason that this works is once … | |
Re: [QUOTE=theoddmonkey]I have two snippets of code that I am having a lot of trouble with finding the closed form Summations and time complexities for: x=0; for(i=1;i< pow(2,N); i = 2*i + 2){ for(j=1;j<N ; j++){ x=x+j; } } and: x=0; for(i=1;i <= (2*n); i++){ for(j=1; j <= n; j++){ if(j<i) … | |
I have downloaded the free Borland compiler Bcc32 and am delighted with it. I also downloaded the turbo debugger. I have a lot of experience using a debugger from an integrated environment but the Borland download includes only the command line version of the compiler and I don'y know how … | |
Re: Good for your compiler! The stored value of a floating point number has a limited precision, probably 50 or 60 bits. This is equivalent to a certain number of decimal digits, say about 15. If the computer were to give you a 20 decimal digit answer the last few digits … | |
In using "cin" for getting input I have about a 99% success rate. In the remaining 1% of cases the program does not pause for input. What causes this and how does one fix it? In ancient times when we programmed in C rather than C++ the same problem occurred … | |
Re: [QUOTE=1o0oBhP]whilst we're on the subject is there a lib function for integer to string ect....[/QUOTE] Yes. itoa is the name of the function. There are corresponding functions for long or double to string. Here's an example. [code] #include <stdlib.h> #include <iostream.h> main() { int val; char st[10] val = 5 … | |
Calling all Dev_C++ users, Here's a mystery! The following little program, which determines whether one integer is a divisor of another or not, compiles and runs fine using Borland's bcc32. [code] #include <iostream> using namespace std; bool divides(int,int); main() { int a,b; char ch; cout << "Enter a then b: … | |
Re: I ran it and it works ok. In response to the prompt you enter a, then a space, then b, then a carriage return. You can also respond a, carriage return, b, carriage return. Your comments indicate that you expect it to do something after you enter a. What it's … | |
I have a question on external variables in a multifile program. Quoting from K&R (first addition, page 72) "By default, external variables are also "global", so that all references to such a variable by the same name (even from functions compiled separately) are references to the same thing." Here's an … | |
Re: You seem to have computed the average correctly. The most efficient way to compute the standard deviation is to use the formula st. dev. = sqrt( (sum of squares -ct*square of av)/(ct - 1) ) so what you need to do is have another variable, say sum2, which, like sum, … | |
Re: The original posting (minah1984) seems to be using the definition of gcd to find the gcd. That's not a bad idea. The one thing missing is that he/she doesn't know how to tell whether i is a common divisor of j and k or not. Here's how to do that: … | |
Attached is a tiny program in which the function F has as an argument the function pointer double (*f) (double). F returns the sum f(1)+f(2)+f(3)+f(4). (Naturally, I have a much more interesting application in mind, but this simple example makes the point.) What I really want to do is replace … | |
Re: There are a number of problems with your program. The main one is that, while it prints out a lot of stuff that you don't need to see, it never performs the tests it's supposed to. Where do you test to see whether the i numbers a, a^2, a^3...a^i are … | |
Re: I think that your "pseudocode" suffers from imprecision. If you tried to turn it into code in some language that you know (C, Pascal, Basic, or whatever) you'd see the problem. You could also check it out by making up a data set and try carrying out the exact program … | |
Re: Might it be that "employees" is ambiguous? It's both the name of the an array of integers and it's also a type that you've defined. (struct employees). | |
Re: One problem is that you'r not correctly initializing the variables in calcCNR. The last variable is where the result appears. When you call the function this variable has no significant value. I'm surprised that the compiler let you get away with the statement "anwer = *cnr". The initial value of … | |
Re: Here's an idea for how to partially solve the problem. I'm assuming that this is not for a first course in programming or CS. Specifically, I'm assuming you've studied trees (not just binary trees). If there's a more elementary way to do this problem I'd like to know about it. … | |
Re: I don't know what "unnormalized" means, but here's how to write it as a normalized floating pt. number: Since the smallest pwer of 2 bigger than the given number is 32, write it as 21.426304 = 32*0.669572, so the exponent is 5 and the significand is .669572. You've got to … | |
Re: This looks like a variation on binary search. It divides the range a1..an into three equal pieces (roughly) and uses two comparisons to determine in which third x lies. The worst case occurs (I think) if x is not on the list and also if x = a(n-1). The number … | |
Re: First, a tangential comment. Your function "addem" has a problem. You want the answers to appear in the variables na and da, so you'r asking the function to change the value of variables on the parametr list. You can't do this successfully unless you make them reference variables. (i.e., just … | |
Re: I have 2 questios. 1: what do the error messages say? 2: It looks to me like the whole program is turned into a comment! If not, whats the /* doing? | |
Re: Here are a few observations. 1: Your class has only public members. You're probably supposed to make the variable members private. (This isn't required by C++, but what's the point of classes if you make the variables public?) 2: You use the word "void" to indicate no arguments, as in … | |
Re: [QUOTE=Asif_NSU]After having us write codes to convert decimal numbers to another base my faculty has now asked me to write codes to convert a number from ANY base to another. He explains that itz simple since i already wrote the program to convert integer to another base. So i just … | |
Re: [QUOTE=fopah]i am trying to make a program that displays to the screen the prime factors of a given number. i have it all the way to the prime number checking i dont quite understand how to extract the prime numbers any help would be much appreciated[/QUOTE] I'm not sure I … | |
Re: For starters, you'll need 2 constructors. One will be something like rational(int m, int n) { num = m; den = n; //You really should check for n == 0 } and the other (the default) would be rational() { num = 0; den = 1; } In order to … | |
Re: You don't need a private function here. Also I don't think it's a good idea to make the numerator and denominator doubles. For one thing, they may not print out properly, i.e., you may have a fraction 3.0/4.0 where you really want 3/4. Attached is a simple fraction program. (It … | |
Re: [QUOTE=akila]I have a simple program to figure out the single machine precision (epsilon). According to C, float precision is 1.2e-8, but I'm getting the double precision, 2.2e-16. I can't figure out how else to force single precision? [code] void main(void) { float eps = 1.0f; while( eps + 1.0f != … | |
Re: [QUOTE=jwenting]headerfiles are not compiled, clear and simple. .o files are compiled compilation units which have not yet been linked, header files are not compilation units.[/QUOTE] That's my understanding too, but a couple of weeks ago I asked a question in this forum about a header file like this: [code] // … | |
Re: [QUOTE=Asif_NSU]well dont know much about C++ standards, but this is what was written in page no 193, The C programming Language(second edition) by K & R: So i think in C the type of integral constants are very much defined. U might want to go here [url]http://www.lysator.liu.se/c/schildt.html[/url] and see section … | |
Re: In the first case the outer loop (i loop) repeats N times and for each repeat of the outer loop (i loop) the inner loop repeats N times. As you wrote this program, the k loop runs once, having nothing to do with i or j, so whatever the loop … | |
Re: When you get your program running your in for another surprise. Your program will say, for instance, that 3/5 = 0. The problem is that onefraction.num and onefraction.den are integrs and when you divide integers you just get their integer quotient. Something like this will work: decimal = (1.0*onefraction.num)/onefraction.den;, or … | |
Re: If you're using the installation instructions that Borland supplies you might have been led astray by the statement that tells you to put into the config file the line. -I"c:\Borland... That first letter, upper case I, looks very much like lower case l in the font Borland uses. That error … | |
I've seen a number of listings which include some pre-proccessor stuff that I don't see the need for. Here's an example. The file is a header file ADD.H. Here is the whole file: ___________________________________________________________________ #ifndef ADD_H #define ADD_H (Some function prototype which is just what you'd expect in a header … |
The End.