Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

use C++ Project 6 1. Using vectors or arrays, write a function named word_rev()

ID: 3848671 • Letter: U

Question

use C++           

Project 6

1. Using vectors or arrays, write a function named word_rev() that reverse any given word.

2. Write a program that will:

Ask the user to enter a word.

Save the entry as word_entered.

Call word_rev on the entry

Display the reversed entry (word_entered)

3. Write a function named prime() that determine whether or not a given number n (greater than

one) is prime. The algorithm:

If n is even then n is not a prime number except n = 2

For all odd numbers less or equal to the square root of n, if any of them divide n, then

n is not prime

4. Write a program that:

Asks the user to enter an integer

Saves the entry as var

Calls the function prime() on the entry

Displays whether or not the entry is prime

5. Write a function named eratos() that find all the prime number less than a given number, its

argument n

6. Write a program that:

Asks the user to enter an integer

Saves the entry as bound

Passes bound onto eratos()

Displays all the prime numbers less or equal to bound

Explanation / Answer

using namespace std;
#include<iostream>
#include<cstring>

bool prime(int n)
{
   bool flag=true;
   int i;
   if(n%2==1){
   for(i=2;i<=n/2;i++){
       if(n%i==0){
           flag=false;
           break;
       }
   }
}
   return flag;
}

void eratos(int bound){
   cout<<" the prime numbers are :";
   for(int i=2;i<=bound;i++){
       if(prime(i))
cout<<i<<" is Prime number";
}
}

int main(){
  
   char word_entered[20];
   char word_rev[20];
int n;
int bound;
int var;
   cout<<" enter a word : ";
   cin>>word_entered;

strrev(word_entered) ;
   cout<<" word reversed : "<<word_entered;
  
   cout<<" enter a number : ";
   cin>>n;
   if(prime(n))
cout<<n<<" is Prime number";
else
cout<<n<<" is not prime ";
  
  
       cout<<" enter a number : ";
   cin>>var;
       if(prime(var))
cout<<var<<" is Prime number";
else
cout<<var<<" is not prime ";


       cout<<" enter a bound : ";
   cin>>bound;
eratos(bound);

   return 0;
}