#include
#include
bool is_prime(unsigned num) {
unsigned max, factor;
if (num<2) return false;
if (!(num%2)) return num==2;
max = (unsigned) sqrt((double)num) + 1.0;
for (factor=3; factor
return true;
}
int main() {
unsigned num;
for (num=1; num<=200; ++num)
if (is_prime(num)) printf ("%u is prime\n", num);
return 0;
}
Implement these methods in JAVA, perhaps with minor changes to primes():
public static void primes() {
for(int i = START; i <= END; i++) {
if(prime(i))
System.out.print(i + ", ");
}
System.out.println();
}
public static boolean prime(int n) {
if(n < 2) return false;
if(n 0) return false;
return true;
}
How do Iwrite a Program that prints all prime numbers from an array?
You can loop through the array. In Java, this might look like this:
for (i = 0; i <= myArray.length(); i++) {
System.out.println(myArray[i]);
}
Write a program using recursion which should take two values and display 1st value raised to the power of second value.
//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include<stdio.h> #include <string.h> int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
ALGORITHM SAMPLE i = 0 REPEAT OUTPUT ("Enter a number: ") INPUT (number[i]) i ++ UNTIL (number[i] 0) THEN counter++ sum = sum + number[i] END IF END FOR DISPLAY (counter) DISPLAY (sum / counter) END SAMPLE
Identification division. Program-id. Quadratic. Environment division. Data division. Working-storage section. 01 a pic 9(3) value 0. 01 b pic 9(3) value 0. 01 c pic 9(3) value 0. 01 d pic 9(3) value 0. 01 e pic 9(3) value 0. 01 f pic 9(3) value 0. 01 g pic 9(3) value 0. 01 h pic 9(3) value 0. 01 x1 pic 9(3) value 0. 01 x pic z(3).z(2) value 0. 01 x2 pic 9(3) value 0. 01 y pic z(3).z(2) value 0. Procedure division. Display "Written by Martin O. Egua, but not complete". Display "Quadratic equation solver for three values a, b & c" Display "Enter a number: " Accept a. Display "Enter the second number: " Accept b. Display "Enter the last number: " Accept c. compute d = (b * b) compute e = 4 * a * c compute f = 2 * a compute g = d - e compute h = function sqrt (g). compute x1 = (-b) + h compute x = x1 / f Display "X = " x compute x2 = (-b) - h compute y = x2 / f Display "Y = " y Display "Send the accurate program". Stop run.
A negative number is prime if and only if its absolute value is prime.
Write a program using recursion which should take two values and display 1st value raised to the power of second value.
Negative numbers can be classified as either prime or composite because they still have their absolute value
The answer will depend on the value of ay.
The following PHP Code will display the prime numbers between 2 and 50.You know that 1 is not a prime number so edit the value for "first for loop" according to your requirements (you can also do it for 2 to 1000 or from 900 to 929)Output will be:2is a prime number3is a prime number5is a prime number7is a prime number11is a prime number13is a prime number17is a prime number19is a prime number23is a prime number29is a prime number31is a prime number37is a prime number41is a prime number43is a prime number47is a prime number2013-02-22: Replaced $i/2 with sqrt($i) for efficiency by Ryankirgan
The answer will depends on the value of W.
Identification division. Program-id. Prime. Environment division. Data division. Working-storage section. 77 n pic 9(3). 77 q pic 9(3). 77 r pic 9(3). 77 i pic 9(3) value 1. Procedure division. Para-a. Display ( 1 , 1 ) erase. Display ( 2 , 1 ) "enter an integer:". Accept ( 2 , 20 ) n. If n = 1 display ( 3 , 1 ) "number is not prime" go to stop-para. Para-b. Add 1 to i. If i = n display ( 3 , 1 ) "number is prime" go to stop-para. Divide n into i giving q remainder r. If r = 0 display ( 3 , 1 ) "number is not prime" go to stop-para. Go to para-b. Stop-para. Stop run.
It is 0. Two of the first 51 prime numbers are 2 and 5, whose product is 10. When you multiply 10 by any other whole numbers, the final digit (in the ones place value) will be 0.
The answer depends on what value C has.
Prime factorization of 115 is: 5x23 Prime factors are the prime numbers multiplied with each other that together form the original numerical value. Prime numbers are numbers that have no factors besides one and itself. The first prime number is 2, then 3, 5, 7, 11, 13, and so on. Sometimes one may have a number that has multiple same prime numbers for its prime factorization; for example the prime factorization of 256 is 2x2x2x2x2x2x2x2
see the program
Min gets the lowest of a range of values. Max gets the highest value. Sum adds numbers together. So if you had numbers in all the cells from A1 to A20 then: =MIN(A1:A20) will display the lowest value out of all the numbers. =MAX(A1:A20) will display the highest value out of all the numbers. =SUM(A1:A20) will give the total of all the numbers added together.