#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;
}
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
import java.util.Arrays; import java.util.Scanner; public class Answers { public static void main(String[] args) { //Creates a scanner object named console. Scanner console = new Scanner(System.in); //Variabels int [] numbers = new int [10]; double avg = 0.0; double median = 0.0; int max = numbers[0]; double count = 0.0; //User input. for (int i = 0; i < numbers.length; i++){ System.out.print("Number: "); numbers[i] = console.nextInt(); } //break System.out.println("==============="); //finds the average and max value. for (int i = 0; i < numbers.length; i++){ count += numbers[i]; avg = count / numbers.length; //average if (numbers[i] > max){ //finds the max value. max = numbers[i]; } } median = (numbers[4] + numbers[5])/2; //Median value //Display to user. System.out.println("Highest value found: " + max); //Show maximum value found in array System.out.printf("Median is: %.3f \n",median); //Show median System.out.printf("Average is: %.3f \n",avg); //Show average sortAsc(numbers); //Print out whole array ascending } //Method for sorting an Array ascending. public static void sortAsc(int [] array){ for (int i = 0; i < array.length; i++){ Arrays.sort(array); System.out.println(array[i]); } } } This should do everything you asked for, hope this helps!
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.
see the program
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
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.