![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
how to use .cpp in php??
Ok here is the thing
![]() I have some knowledge in php and almost none in c++, because i decided to go with java, so bare with me. Today a friend asked me to do some homework for him, cause he ran out of time and wont be able to do it alone. I had to create a program that returns numbers that can not be divided with anything but 1 and itself. so if i put in number 10, it returns numbers 2, 3, 5, 7. I hope you understand what i mean. Ok this was easy and here is the code: (some in slovenian language) #include <iostream.h>
int main()
{
int d=3;
int c=d;
cout<<"Vpisi stevilo n, do katerega bo po intervalu od 0 do n"<<endl<<"program izpisal prastevila: ";
cin>>c;
if(c%2==0)
c++;
cout<<"1"<<endl<<"2"<<endl;
while (d!=c)
{
bool prastevilo=true;
for(int i=2; i<d ; i++)
if(d%i==0)
{
prastevilo=false;
i=d;
}
if(prastevilo==true)
cout<<d<<endl;
d++;d++;
}
return 0;
}Now what i need to do is use this in php, which i have no idea how that can be done. But lucky for me i have an example how all together should look and work. If anyone has any ideas or an advice plz let me know, and even better if you have the time to make this for me plz help me. Anything will help so post tutorials, articles, even a simple hint how to do it can get me closer to the solution of this problem. Thank you and have a nice day Vizy |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Don't know what those numbers are called in Slovenian, but in English they're called "prime numbers." Here's some code I wrote in another thread:
int prime = 1;
if (number == 1) {
prime = 0;
/* 1 is not a prime number */
}
else {
for (int i = 0; i < sqrt(number); i++)
{
if ((number / i == (int)(number / i)) && i != 1 && i != number)
prime = 0;
/* i is a factor that is not 1 or the number itself - the number divided by i is the same when converted to an integer. */
}
}
if (prime == 0) {
printf("%i is not a prime number.", number);
}
else {
printf("%i is a prime number.", number);
}Enjoy. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
Hey thnx for the reply, but that is not what i need. I need to know how can i include this .cpp code into my webpage. I really dont know how to do it. (applets in java are so simple
)thnx and cya |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
The only way you can execute CPP code from your web is through CGI. Configure your ouput from the C++ prog with CGI/HTML headers... then do all the other "wonderful" things needed... followed by crossing your fingers that your host provides support for CGI scripts on your page.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() |
yeah CGI is a bitch to setup if you don't know what your doing.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#6 |
|
Professional Programmer
|
/me loves the CGI, makes me wanna drink, which is a good thing
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|