|
The question goes as follow.
1. Write a c++ program that finds and prints all the prime numbers less than 100. (Hint:For each number from 2 to 100, find reaminder = number%n, where n ranges from 2 to sqrt(number). If any remainder equals 0, the number is not a prime number.)
2. Write a c++ program that calculates the nth number in the Fibonacci sequence, where the user enters n into the program interactively. For example, if n=6, the program should display a value of 5.The Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13...; the first two terms are 0 and 1, and each term thereafter is the sum of the two preceding terms-that is, fib(n)=fib(n-1)+fib(n-2).
I have tried to run but my program would not work. would anyone please help me out with this. thank you.
|
|
|
|
|
What exactly would not work?
|
|
|
|
|
after compiling the prime number question, the output of my program shows some weird numbers like 20887633892
20887633892
20887633892
|
|
|
|
|
I'm sorry but my powers of divination are not working today. Can you give us a clue as to the code involved in producing these values? Please try and narrow the problem down to the actual statements that cause the problem, and the input values to whatever algorithm you are using.
|
|
|
|
|
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main()
{
int num, n, remainder, prime, nonprime;
remainder = num % n;
for(num=2; num<=100; num++)
{
for(n=2; n<=sqrt(num); n++)
{
if(remainder==0)
break;
else
num=prime;
}
cout<<prime<<" "<<endl;
}
getche();
return 0;
}
|
|
|
|
|
aihcezs144 wrote: remainder = num % n;
aihcezs144 wrote: num=prime;
I suggest you use the single-stepping capabilities of the debugger and either "watch" some variables or add some statements to print intermediate values, as there are major problems with your code.
Is this your first attempt to programming? FYI: statement order is important, and assignment statements work one way (right to left), not both ways (as in mathematical equations).
|
|
|
|
|
okay, i've tried a new one but there are sompilation errors of which i could not locate. would you please take a look and tell mw where did i go wrong. thank you
#include <iostream>
#include<cmath>
#include <conio.h>
using namespace std;
int main()
{
int num, n, remainder;
remainder=num % n;
for( num = 2; num <=100 ; num++ )
{
for (n=2; n<=sqrt(n); n++)
{
if( remainder != 0 )
break;
}
if(remainder)
{
cout <<num<< " ";
}
num++;
}
getche();
return 0;
}
modified on Friday, September 4, 2009 8:20 AM
|
|
|
|
|
Seems you have removed one problem.
Compile-time and often run-time errors contain file name and line number information, use it to your advantage; and tell your IDE to always show line numbers in edit windows (for Visual Studio look here[^]).
I'm not going to provide any more help, the goal of exercises like these is for you to learn how to research, analyze, and debug; and not for others to do your work.
|
|
|
|
|
aihcezs144 wrote: remainder=num % n;
Note that remainder will not change if either num or n or both do, it's just set to num%n (which looks like an invitation to a division by zero) once when that statement is executed.
|
|
|
|
|
Hi,
Would you give me an example of FAMILIES of functions that I could use in a Hashtable?
Notice that I need a FAMILY of functions (that means it should depend on some random constants previously defined)
It should go from {0, K} to {0, m}
Im trying
f(x) = (a*x + b) % prime % m
where prime is larger than x, a is between 1 and prime-1, and b is between 0 and prime-1
But its not good enough.. Dunno why though
|
|
|
|
|
Quake2Player wrote: Would you give me an example of FAMILIES of functions that I could use in a Hashtable?
Example: SHA family[^]. This family and additional hash function implementations can be found here[^].
Also you can find some different hash function implementations here[^].
Regards,
Nuri Ismail
|
|
|
|
|
Hi
I got an Access database encrypted by an application I bought years ago and I don't have that application anymore. This application encrypted everything before saving into the database and I would like to recover some data from that DB.
I am not sure but I think this algorithm needs a key and keys are saved to the database too so I got the keys. But I am not sure about the keys having a role in encryption. This algorithm produces a ciphertext which has same the same length as its cleartext.
Here are some examples:
Cleartext Encrypted Key
Harita Mühendisi KXsmaX büpxfdmYm MA%7vbxWKIAgARC71+KEn8i3M4yIa+i6Zd384GWTZ6/bT+M+mKCKEFN35meeSE1OGzcxL8ukvvSeKh9c5o2bBF7vbZ+_14
ÇONA ÇkWq MA%vPz9ClelvBm24BrRcVmsXPtD7OOie8xG73DumSdNLlSaAIhL7L5uPB+Q5+titBzXRDisXC4NnnEWoESLU2VIx845_16
I can provide more examples if needed but I don't think they will help. As far as I know if you encrypt a text with this algorithm and use the same key every letter means another letter. For example if you look at the first example H means K, i means m. If you want I can send you the database in private.
I really need you help.
Thanks.
|
|
|
|
|
Only jones can help you, tell them that spider sent you.
|
|
|
|
|
I'm aware that it's complicated.
|
|
|
|
|
SimpleData wrote: I'm aware that it's complicated.
I think that may be an understatement. In order to decrypt the data you will at the least need to know the algorithm that was used to encrypt it. Added to that the encryption may have been done with a key that the user has to enter (similar to entering a password). Without these elements I think you may be facing an uphill struggle.
|
|
|
|
|
I don't know which encryption algorithm used to encrypt it but I thought that someone here might recognize the output and tell me which algorithm may have been used. Maybe someone could see a pattern etc.
I am sure that no password is needed while encrypting. Only this random key may have been used.
|
|
|
|
|
The whole ethos of encryption is that it should be impossible to decrypt the data just by looking at the encrypted characters. What is the point of encrypting secure information if anyone can decrypt it just by looking at it?
Do you have the original program that did the encryption, or access to the people who wrote it?
SimpleData wrote: I am sure that no password is needed while encrypting. Only this random key may have been used.
I don't think that encrypting with a random key would be a good idea!
|
|
|
|
|
I don't have the application encrypted it all I have is this database right now so I can't reverse engineer it. It is not a well coded application actually and I don't think that it's really secure.
I wasn't talking about just looking at the encrypted text and solving it from your mind, maybe something may catch to your eye. Like realizing something was encoded with Base64 just by looking.
Random key for each raw is included in the database.
|
|
|
|
|
A few observations:
-1- Decoding an encrypted message without the key or algorithm will in general be hard enough that nobody's going to want to bother if they're not getting paid.
-2- If the encryption algorithm is decent, decoding will essentially be impossible.
-3- This particular algorithm doesn't seem very good.
-4- Cleartext characters outside the range [A-Za-z] are unchanged.
-5- There seems to be a 1:1 correlation between cleartext characters and encrypted characters. For example, in the first line, both "a"'s map to "X" and all of the "i"'s map to "m".
-6- The key appears to be base64 encoded. Running the portion between the "%" and the "_" through a base64 decoder may make clear what it represents. Probably a translation table.
|
|
|
|
|
In another words it looks like a ceasar's cipher, and my guess is that the number after "_" indicates the alphabetical shift or something, and the characters between % and _ represents the "replacment alphabet" somhow. And if it is indeed a ceasar's chiper it looks lika a copy-pasta job, since its range is a-Z and skipps your countrys special characters.
modified on Tuesday, September 1, 2009 3:41 AM
|
|
|
|
|
Thank you for really useful tips. If I try to decode everything between % and _ I get meaningless text. I know ceasar's cipher because I've read Digital Fortress .
This algorithm also changes numbers. I couldn't include a number example but it does. I think we've made progress, we will solve this.
|
|
|
|
|
Have you by any chance tried the common Algoprithms? Blowfish, Catfish etc?
BHM
|
|
|
|
|
|
Originally, I want to use the Markov model to realize object tracking and I have found Markov Random Field can be used for the optimizing Multiple target tracking.
However, the background of my tracking project is changing because of the movement of the camera.
So, I want to know whether mean-shift(or HMM, Markov model)can be used for target tracking at this kind of moving background.
And, if it is recommendable for me to combine Markov Random Field with mean-shift for producing a result of robust muti-target tracking.
Thank you.
modified on Friday, September 11, 2009 11:12 AM
|
|
|
|
|
Greetings,
I'm trying to determine the best way to get a polygon from a set of points. The points are not in any particularly useful order (they are the endpoints of individual lines that fill the polygon in question). How can I easily take such a set of points and figure out the vertices of a polygon from them? The polygons may have gaps inside of them. Any ideas?
Thanks,
Will
PS. Sorry about the repost from the Graphics forum. I wasn't sure whether to put it here or there, but was informed that here was a better choice.
|
|
|
|