An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. a) Write a function that determines whether a number is prime.
Q: 5. An integer is said to be prime if it's divisible by onlv 1 and itself. For example, 2, 3, 5 and 7…
A: int isPrime(int n){ for(int i=2;i <= n/2;i++) { if(n%i==0) {…
Q: In Python: can you this problem be solved without using "while" and "for". Write a function called…
A: We need to write a program in python that takes the input of an integer between 1 and 50. program…
Q: 6. Write a function which takes only your full name as input and finds the total number of vowels in…
A: Please find the program to display count and vowels in the given input name:
Q: Write a function that computes the area of a triangle given the length of itsthree sides as…
A: import math def Area_of_Triangle(a, b, c): # It will calculate the Perimeter Perimeter = a…
Q: 3. Twin Primes A prime number is any integer greater than 1 that is divisible (without remainder) by…
A: Program: def twinPrimes(a,b):t=[]while a<=b:if a==1 or a==2:a+=1continueif isPrime(a):if…
Q: An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For…
A: below is the HTML-JavaScript for a and b
Q: What is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10) [this…
A: The output of the code is 1.
Q: What is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10) [this…
A: Solution :
Q: Write a function that displays all the numbers between two integers in n lines, that are divisible…
A: Required: Write a function that displays all the numbers between two integers in n lines, that are…
Q: Use C++ coding A “Perfect” number is a positive whole number that is the sum of its proper divisors…
A: #include<iostream>using namespace std;int main(){ int n; cin>>n; int sum=1;…
Q: hey i need to write a function that recieves a number of arguments using a continue statement, skip…
A: - We need to highlight the code for the asked scenario. - We are using Python here.
Q: Prompt: In python language, write a function that give that find the total number of alphanumeric…
A: A string is a sequence of characters with a variable name. Each character element may be referenced…
Q: . Create a function that accepts two numbers as input arguments and returns one with the larger…
A: clc; clear all; x=large_absolute(-9,-6); %calling function large_absolute with 2 arguments to…
Q: Q2\A) Write a function that finds the factorial of an integer, the main program calls the function…
A: Factorial of a number n is calculated as the product of numbers from 1 up to n is called the…
Q: I need a function that takes in a string& and returns a void that outputs a string with "my" at…
A: Note: Comments have been added in the source code itself to have a better understanding of the code.…
Q: Engineers usually measure angles in degrees, yet most computer programs and many calculators require…
A: Since you have not mentioned your preferred programming language, we will be solving this using…
Q: If a year has the digit 7 OR the digit 4 in it, then it is called a “Beautiful year”. For example,…
A: Solution: Define the function called year_cotains() Inside the function declare 4 and 7 of string…
Q: Write a function that takes one argument, an integer, and returns the value of the following…
A: For First Part- Code is- #include <iostream>#include<cmath>using namespace std; int…
Q: The following function is defined on the set of integers. Write a program, that calculates the…
A: I have given an answer in step 2.
Q: Create a function that returns the sum of all even numbers from 1 to 40.
A: Following is the code written as asked in question to give a sum of all the even numbers from 1 to…
Q: 1. Write a function which checks whether the sum of positive divisors of given input is equal to the…
A: Answer
Q: Pressure in U.S. customary units is measured in psi (pound per square inch) In SI metric units…
A: Actually, MATLAB is a programming platform designed specifically for engineers and scientists.
Q: Write a function that returns the power of 2 (x) of a given number, keep asking the user to enter…
A: Please find the answer below :
Q: Write a program to find the first n numbers of the Fibonacci series. You have to take a positive…
A: program to find the first n numbers of the Fibonacci series. You have to take a positive number from…
Q: Q6: The volume of oil stored in an underground 200-foot deep cylindrical tank is determined by…
A: As there is no programming language mentioned program is attempted in c++ language user has to…
Q: Write a function that displays all the numbers between two integers in n lines, that are divisible…
A: Program: A program is used to interact with computer systems and solve complex problems. The main…
Q: In this question you need to write a program and execute it with the given input, the output of your…
A: python program to check Islamic year: def checkLeap(year): return ((11*year + 14)%30) <…
Q: 2) The ceiling of a floating-point number x is the smallest integer that is still larger than or…
A: Actually, python is a easiest programming language. It is a structural and object oriented…
Q: Explain 7kyu Square Every Digit 1818315 90% of 20,64970,162 of 196,097 Mysterious Magenta A 1 Issues…
A: Answer: Algorithms: Steps1:we have create a function name as square_digits that taken an arguments…
Q: Flesh out the body of the print_seconds function so that it prints the total amount of seconds given…
A: Given a time in hours, minutes, and seconds, print the time in seconds. 1 hours = 3600 seconds 1…
Q: Write a function called print_multiples that takes in a number and prints out 10 multiples of that…
A: Required: to create a function that can print 10 multiples of a given number. Required code with…
Q: 1. The distance between points with coordinates (XA, YA) and (XB, YB) is given by 2 J(XA-XB)…
A: Since the programming language is not mentioned, I am using C++ programming language.
Q: Write a function called pizza_cost that returns the cost per square inch of a circular pizza given…
A: Please find the answer below :
Q: 3. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program to…
A: // C++ program #include <iostream> using namespace std; //takeinput function int…
Q: Please complete the following function printBox, which accepts three parameters (i.e., char c, int…
A: Here is the detailed and simplified code for the above listed problem statement:
Q: I need a function that returns void and outputs a string from lowest to highest according to an…
A: For the given string “Hello World!” the output string from lowest to highest according to American…
Q: Write a function that takes a gross salary and calculates the net salary by deducting: • 7.65%…
A: PROGRAM: #include<stdio.h> //Defining the method to calculate the net salary with parameters…
Q: An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For…
A: As there is no mention of perticular language I am writing java. I am showing the output of 1 to 100…
Q: Q2/Write a program that reads from the user the value of x and apply the function below: * x+4 12 >…
A: For these questions we have to first extract the code flow and then accordingly make a C++ code for…
Q: An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For…
A: Given: An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For…
Q: What is wrong with the following code segment... Given the following function to find the minimum of…
A: C ++ code to find the minimum of two number
Q: Write a function that displays all the numbers between two integers in n lines, that are divisible…
A: Programs: The general purpose of the program is to solve complex problems and establishing the…
Q: 1)Write a function in Python that takes four parameters a, b, c and n and then checks to see if…
A: python code is given below:
Q: Use C++ Write a program whose input is a character and a string, and whose output indicates the…
A: Answer: Here Step 1: taking the user inputs of type character and string Step…
An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not.
-
a) Write a function that determines whether a number is prime.
-
b) Use this function in a script that determines and prints all the prime numbers between
1 and 10,000. How many of these 10,000 numbers do you really have to test before
being sure that you have found all the primes? Display the results in a <textarea>.
-
c) Initially, you might think that n/2 is the upper limit for which you must test to see whether a number is prime, but you need go only as high as the square root of n. Why? Rewrite the program using the Math.sqrt method to calculate the square root, and run
it both ways. Estimate the performance improvement.
Please write the code in JavaScript HTML5.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images
- Display the first N magic numbers, where N is a positive number that the user provides as input. Here, a magic number is a number whose sum of its digits eventually leads to 1. For example, 1234 is a magic number because 1 + 2 + 3 + 4 = 10 and 1 + 0 = 1, while 1235 is not (1 + 2 + 3 + 5 = 11 and 1 + 1 = 2). Write a program that prints out the first N magic numbers, seven on each line. You are required to use the following function prototype: bool isMagic(int value); // Returns true if value is a magic number The outline of this function will be as follows: Step 1: Calculate the sum of digits of the value Step 2: Repeat Step 1 until we get a single-digit Step 3: If the resulting sum is equal to 1 then it is a magic number, otherwise not Here is the sample output:If a year has the digit 7 OR the digit 4 in it, then it is called a “Beautiful year”. For example, 2017, 2014, and 2072 are all beautiful years. If the year has BOTH 4 and 7 in it, then it's an “Amazing year”. For example, the years 2047 and 2074 are amazing years. All other years are “Ugly years”. You need to write a function that takes a year as an argument and return it's type. Then, finally print the returned values in the function call. ================================================ Sample Function Call 1: function_name(2470) Sample Output 1: Amazing year ================================================ Sample Function Call 2: function_name(2170) Sample Output 2: Beautiful year ================================================ Sample Function Call 3: function_name(2021) Sample Output 3: Ugly yearWrite a function that asks the user how many Fibonacci numbers to generate and then generates them. Make sure to ask the user to enter the number of numbers in the sequence to generate. The Fibonacci sequence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, § You could assign your input integer to a variable num by num = int(input("How many fib. numbers you want to generate?:")). § You have to consider exceptions, such as the input integer is zero, negative numbers or floats. § Please submit your code and console screenshots to Blackboard. Code containing syntax error will be graded zero. § Example: The prompt asks, “How many fib. numbers you want to generate?
- What is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10)[this function multiples all arguments together (except t) and raises the result to the power of t and returns this]print(mystery_func(2, 3))What is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10)[this function multiples all arguments together (except t) and raises the result to the power of t and returns it]print(mystery_func(num = 9, input = 3, t = 1, y = 1))Write a function that takes a gross salary and calculates the net salary by deducting: • 7.65% for FICA • x for federal taxes • y for state taxes • z for local taxes Also, deduct $75 for parking fees and $22.50 for a gym membership. The federal tax rate must be between 10 and 37 percent. The state tax rate must be between 3.25 and 11.33 percent. The local tax rate may not be greater than 3%. If any of those values are outside the valid range, return INVALID_PERCENTAGE from your function. Federal, state, local taxes, and gym membership amounts should be passed in by value. FICA and parking should be a global constant. COMPUTER LANGUAGE IN C
- 3 Write two different functions which have the following results with input 1 and 2. It means that these two different functions are equivalent at input 1 and input 2.What statement about the print() function is true? A. print() has a variable number of parameters. B. print() can have only one parameter. C. print() can be used to obtain values from the keyboard. D. print() does not automatically add a line break to the display. After a function calculates a value, how does it return that value to main program where it was called? A. By including that value in a return statement. B. By using the print() function C. By storing the value in a local variable. D. Since function variables are destroyed when the function call is completed, the calculated values are destroyed as well. Where in a program should a function be defined? A. At the very end B. Immediately after the first call to the function C. Near the top of the program D. Functions do not have to be defined to be usedMake a function that determines if a triangle is equilateral, scalene, or isosceles given the length of the sides of the triangle. In the main function, prompt the user three times to input three numbers using the prompt()function. These three numbers are the measurements of the length of the sides of the triangle. Make sure that the user is typing numbers. Use the isNaN() function to check. To implement this, you can declare three variables and the value for each variable is a prompt for the user. Refer to the sample below: var a = prompt(); var b = prompt(); var c = prompt(); Create a function determineTriangle(a, b, c) that accepts the three numbers from the user as input. The output of the determineTriangle(a, b, c) function is the type of the triangle. Use if..else statements for this feature. If all three sides of the triangle are equal, then output “The triangle is EQUILATERAL.” If only two sides are equal, output “The triangle is ISOSCELES,” else, output “The triangle is…
- Please help me with my homework and needs to be submitted by today. Thank you very much, if you have any questions please let me know. Part 1 Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that takes a as a parameter, chooses a starting value for x, and returns an estimate of the square root of a. while True:y = (x + a/x) / 2.0if y == x:breakx = y Part 2 Write a function named test_sqrt that prints a table like the following using a while loop, where "diff" is the absolute value of the difference between my_sqrt(a) and math.sqrt(a). a = 1 | my_sqrt(a) = 1 | math.sqrt(a) = 1.0 | diff = 0.0a = 2 | my_sqrt(a) = 1.41421356237 | math.sqrt(a) = 1.41421356237 | diff = 2.22044604925e-16a = 3 | my_sqrt(a) = 1.73205080757 | math.sqrt(a) = 1.73205080757 | diff = 0.0a = 4 | my_sqrt(a) = 2.0 | math.sqrt(a) = 2.0 | diff = 0.0a = 5 | my_sqrt(a) = 2.2360679775 | math.sqrt(a) = 2.2360679775 | diff = 0.0a = 6 | my_sqrt(a) = 2.44948974278 | math.sqrt(a) =…I need a function that returns void and outputs a string from lowest to highest according to an ASCII chart such as "Hello World!" becoming " !HWellldoor". Please help me with this problem using c++.Write a function that displays all the numbers between two integers in n lines, that are divisible by 5 or 7 (not by both). So, the function should take as parameters the minimum and maximum of integer numbers and n. If no values are passed to them, this function should display the numbers between 1 and 100 in 10 lines. Write a test program to test your function. *Output of the numbers should be formatted well.