The brute force way would be to iterate through all the integers smaller than the sought number and check the number is divisible by each of them. However this algorithm is extremely inefficient, but improving upon the simple idea, we can come up with an algorithm:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*
*
*/
int main(int argc, char** argv) {
int checked = 72; //put your number that you want to check
int temp = 2; //the temporary variable to check against
char isPrime = 1; //intially assume it is prime
if (checked != 1 checked != 2) {
while (temp <= sqrt((double) checked)) { //only have to check up to the square root of checked
if (checked % temp 0) {
temp += 1; //only have to check odd numbers } else {
temp += 2; } } }
if (isPrime) {
printf("Checked is prime!\n"); } else {
printf("Checked is not prime!\n"); }
return (EXIT_SUCCESS);
}
or a better edited version here: http://img689.imageshack.us/img689/8164/primecodec.png
write a c++program by using if statement to read a number and check whether it is positive or negative
You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.
Type your answer here... i think we should first enter 1 number then check it
Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.
45
write a c++program by using if statement to read a number and check whether it is positive or negative
write a program in C to check whether a given number is apalindrome or not
To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.
8086 assembly language program to check wether given number is perfect or not
Use the Exception class and type converters.
You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.
Active Time spent online
Type your answer here... i think we should first enter 1 number then check it
The program is here guys.......... //Finding whether the given number is perfect or not //Starts here #include<stdio.h> void main() { int i=1,temp=0,number; scanf("%d",&number); while(i<=number/2){ if(number%i==0) temp+=i; i++; } if(temp==number) printf("Its a perfect number"); else printf("Its not a perfect number"); } //ends here
Avogadro's number is a constant. Therefore only one number is equal to Avogadro's number.
Lxi h, 2000h mov a,m mov b,a inx h mov a,m add b sta 2002h hlt
You can do this: <?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }