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
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;
}
use C++ Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse...
C++
Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...
in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){ sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() { int score, highest; //missing portion of the program return 0; } 1(c). Find the missing portion of the following code, so the...
Write a method that determines if a given non-negative integer is a prime number, use the following method header: public static boolean isprime(int n) Prime numbers are integers that are divisible only by 1 and themselves; for example, 2, 5, 7, and 13 are prime numbers, while 15, 16, and 20 are not. By definition, 0 and 1 are not prime numbers. To test your method, write a simple program that asks the user to enter a number and then...
use c++ language, keep it simple i am using code block
Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...
Please use public class for java. Thank you.
1. (10 points) Write a method that computes future investment value at a given interest rate for a specified number of years. The future investment is determined using the formula futurelnvestmentValue numberOfYears 12 investmentAmount X ( monthlyInterestRate) Use the following method header: public static double futurelnvestmentValue( double investmentAmount, double monthlyInterestRate, int years) For example, futureInvestmentValue 10000, 0.05/12, 5) returns 12833.59. Write a test program that prompts the user to enter the investment...
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...
C# Programming: A. Write a GUI program named MultiplicationGUI whose Main() method asks the user to input an integer into a TextBox and then calls a method named MultiplicationTable() after the user clicks a Button. MultiplicationTable() displays the results of multiplying the integer by each of the numbers 2 through 10.
Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...
USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)
Write a program to reverse an integer number by using a function
called reverse. The program reads in an integer number and prints
its reverse order. Note that the function receives the number via a
pointer, and uses the pointer to write the reverse number on the
main function.
The function MUST be used AS
IS:
void reverse(int *n)
Language in C
Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...