Write a function named is_prime

Assignment Help C/C++ Programming
Reference no: EM13339028

A positive integer n is said to be prime (or, "a prime") if and only if n is greater than 1 and is divisible only by 1 and n . For example, the integers 17 and 29 are prime, but 1 and 38 are not prime. Write a function named "is_prime" that takes a positive integer argument and returns as its value the integer 1 if the argument is prime and returns the integer 0 otherwise. Thus, for example,

cout << is_prime(19) << endl; // will print 1
cout << is_prime(1) << endl; // will print 0
cout << is_prime(51) << endl; // will print 0
cout << is_prime(-13) << endl; // will print 0

Reference no: EM13339028

Questions Cloud

Why are academic health centers are vital : Why are academic health centers are vital to research and technology? give 3 examples
What is the output of the loop as it is written : Correct the syntax of the loop so that the logic of the corrected loop corresponds to the formatting of the original loop. What is the output of the corrected loop?
Discuss the potential negative impact of a dominant culture : To prepare: Review "Working With Immigrants and Refugees: The Case of Aaron."
Write a function named digit_name : Write a function named "digit_name" that takes an integer argument in the range from 1 to 9 , inclusive, and prints the English name for that integer on the computer screen.
Write a function named is_prime : Write a function named "is_prime" that takes a positive integer argument and returns as its value the integer 1 if the argument is prime and returns the integer 0 otherwise.
Find the terminal velocity of the sled : A test sled has a mass of 400 kg and is acted on by a thrust force of 200,000 N. It also experiences a viscous drag of 1600•V where V is the velocity. Find the 'terminal velocity' of the sled
Rreasons unrelated to the organ : Transplantable organs become available on short notice--usually because a donor has died for reasons unrelated to the organ. They need to be removed and transplanted very quickly because they only remain fresh for a limited period. Then there i..
What is current in the loop when the torque is at max value : The loop consists of a single turn of flexible conducting wire that is wrapped around a flexible mount such that the dimensions of the rectangle can be changed.
How far downstream does the canoe land : If the river current is 2 m/s (from left to right) and the canoe is moving at 5m/s toward the upper shore at a 60° angle, how far downstream does the canoe land

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Integer arguments representing feet

A constructor that will take a single integer argument representing a whole number of feet • A constructor that will take two integer arguments representing feet and inches respectively • A constructor that will take three integer arguments represent..

  Program that stores a series of numbers in a binary tree

Write a program that stores a series of numbers in a binary tree

  Allow single play a simple two dice game of chance against

Write a program that allows a single Player (the user) to play a simple two dice game of chance against

  Design a phonecall class that holds a phone number

Design a PhoneCall class that holds a phone number to which a call is placed, the length of the call in minutes, and the rate charged per minute. Overload extraction and insertion operators for the class.

  Write program to declare the array of type float

Write down the c++ program which declares the array of 50 components of type float. Initialize array so that first 25 components are equal to square of the index variable.

  Write a program that first prompts the user

Write a program that first prompts the user (repeatedly , if necessary) to supply a single digit(0,1,2..9) The program should repeatedly prompt the user for integer values until a sentinel value of 0 is entered to terminate the program.

  Execute tests and repetitions

Read data from standard input and store them in an array, Execute tests and repetitions

  C++ programming uml diagrams

The goal of this lab is to better familiarize you with polymorphism and the factory design pattern, two key components in Assignment

  Wrtie a function called gen_rand_double_array

Wrtie a function called gen_rand_double_array that generates 900 samples of size 22500 random numbers from U(10, 12). For each of these 900 samples, write a main funciton that calculates the mean and finds the simulated probability that the mean is b..

  Program to compute diameter in centimeters of a steel rod

Write a program to compute the diameter in centimeters of a steel rod, an aluminum rod, and a copper rod, which can withstand a particular compression load.

  Principle ofsuperposition to determine that system is linear

Apply the principle of superposition to determine whether the following systems are linear. Sketch what the plot of the function looks like.

  The main function should prompt the user

The main function should prompt the user for the 2 numbers, call the function to display the correct label, then calculate and display the sum of the numbers. Call the function to display the correct label, then calculate and display the differenc..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd