Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 17th, 2005, 5:47 PM   #1
Vizy
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 Vizy is on a distinguished road
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
Vizy is offline   Reply With Quote
Old Feb 17th, 2005, 7:32 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 18th, 2005, 3:05 AM   #3
Vizy
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 Vizy is on a distinguished road
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
Vizy is offline   Reply With Quote
Old Feb 18th, 2005, 9:44 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Feb 18th, 2005, 9:55 AM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Feb 18th, 2005, 10:00 AM   #6
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
/me loves the CGI, makes me wanna drink, which is a good thing
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC