943,534 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5786
  • C++ RSS
Sep 17th, 2006
1

Need help writing an algorithm for this program

Expand Post »
{
int age;
cout <<"Enter Age"
<< end1;
cin >> age;
cout <<"The age you entered is" << age
return 0
}
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
Crisis757 is offline Offline
1 posts
since Sep 2006
Sep 17th, 2006
0

Re: Need help writing an algorithm for this program

An algorithm is a sequence of steps that describe what a program should do. It is normally written before the program. So, if you can describe step by step what this program does, that is the algorithm. It is not rocket science. Just tell us what you think this program does, in point form. Since this is a small program, you may have to be explicit.

For example.
C++ Syntax (Toggle Plain Text)
  1. Step 1 - Declare an integer variable int
  2. Step 2 - Display "Enter age"
  3. Step 3 - ....
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Sep 17th, 2006
1

Re: Need help writing an algorithm for this program

Here is the definition of algorithm...

http://en.wikipedia.org/wiki/Algorithm
Team Colleague
Reputation Points: 92
Solved Threads: 21
Posting Pro in Training
FC Jamison is offline Offline
436 posts
since Jun 2004
Oct 2nd, 2010
0
Re: Need help writing an algorithm for this program
hey all I am beginner in IT and want to over that , Please i have a problem with algorithm, can you give me tips on how to go about it. here is th problem am trying to solve:

Write the following program and run it.

#include <iostream>
#include <stdio.h>
#include <time.h>

int GCD_Euclid(int x, int y);
int GCD_EuclidRec(int x, int y);
int GCD_Simple(int x, int y);
bool isPrime(int x);
bool isprime_Rec(int x,int z);
using namespace std;
void main(int argc)
{
int x,y;

for(int rep=1; rep<=5; rep++){
srand(time(NULL)*rep);
x= rand()%100;
y= rand()%100;


cout << "GCD of " << x << " and " << y << " is " << GCD_Euclid(x,y) << endl;
cout << "GCD of " << x << " and " << y << " is " << GCD_EuclidRec(x,y) << endl;
cout << "GCD of " << x << " and " << y << " is " << GCD_Simple(x,y) << endl;
cout<<endl;
if(isPrime(x))
cout<<"the number "<<x<<" is prime"<<endl;
else
cout<<"the number "<<x<<" isn't prime"<<endl;

if(isprime_Rec(x,2))
cout<<"the number "<<x<<" is prime"<<endl;
else
cout<<"the number "<<x<<" isn't prime"<<endl;

cout << endl;
}
}
int GCD_Euclid(int x, int y){
while(y!=0){
int r=x%y;
x=y;
y=r;
}

return x;
}
int GCD_EuclidRec(int x, int y)
{
return rand();
}
int GCD_Simple(int x, int y)
{
return rand();
}
bool isPrime (int x)
{
return rand();
}
bool isprime_Rec(int x, int z=2)
{
return rand();
}

Implement the two functions GCD_EuclidRec and GCD_Simple .
Run the program and obtain the output.
Implement the two functions isPrime and isprime_Rec.
Run the program and obtain the output.

Tasks (what to hand in):

Hand in the functions GCD_EuclidRec and GCD_Simple.
Hand in the functions isPrime and isprime_Rec.
Hand in the output of step 3 and 5.
How many steps are needed to find the GCD using the simple algorithm is the value of the first number is q and the second number is d?
If at least one of the two numbers is prime, what is the GCD of the two numbers? Why?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dodo rawash is offline Offline
1 posts
since Oct 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: loop between struct .. but error message
Next Thread in C++ Forum Timeline: File Handling using C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC