Two solutions immediately spring to mind:
Copy this function in your javascript file and call it somewhere
function determine_Odd_Even()
{
var a;
var b;
for(a=1;a<=100;a++)
{
b = a%2;
if(b==0)
{
document.write(a+" is even<br/>");
}
else
{
document.write(a+ " is odd<br/>");
}
}
}
In pseudo-code:
let num := 0;
while( num < 100 )
{ num := num + 1;
print( num );
print( " is " );
if( num % 2 = 1 ) // remainder of division by 2.print( "odd" );
elseprint( "even" );
print( 0x0a ); // newline character
}
In C++, the above pseudo-code can be interpreted as follows:
#include <iostream>
int main()
{ for( int num=1; num<= 100; ++num )
std::cout << num << " is " << (num%2?"odd":"even") << std::endl;
return( 0 );
}
Count from 1 to 100 and test each number to see if it is prime.
To test if a number is prime, use the following algorithm:
If the number is negative, multiply by -1 to make it positive.
If the number is less than 2 then it is not prime.
Otherwise, if the number is even then it is prime if it is 2 (all other even numbers are composite).
Otherwise, if the number has any odd factor in the range 3 to its square root, then it is not prime.
Otherwise it is prime.
Firstly, let's be clear about your interval (the range of values). As written, the whole numbers between 1 and 100 excludes both 1 and 100. That is, the set of whole numbers n such that 1 < n < 100. This may or may not be what you meant, hence it is important to be clear.
When we define algorithms that operate upon a range of values, we always use half-closed range. That is, given two endpoints a and b, we define the range of n such that a <= n < b. It is half-closed because b is excluded from the range (it is one-past-the-end of the range). We denote a half-closed ranges as [a:b). Note the use of parenthesis to close the range, as opposed to the square bracket that opens the range. If we denote the range as [a:b] then both endpoints will be included in the range, thus creating a closed range.
In C Programming, we can implement a half-closed range [a:b) using a for loop:
for (n=a; n
// use n...
}
This is (slightly) more efficient than using a closed range [a:b] because that would require us to check for equality with the second endpoint:
for (n=a; n<=b; ++n) { // closed range [a:b] - includes both a and b // use n...
}
Note that to convert a closed range to a half-closed range, we simply add 1 to b. Thus [a:b] becomes [a:b+1).
To print all even numbers in the half-closed range [min:max) we can use the following algorithm:
// print even numbers in the half-closed range [min:max)
void print_evens (int min, int max) {
if (min%2) ++min; // if min is odd, add 1 to make it even
while (min printf ("%d ", min); min += 2; } printf ("\n"); } Note that we start by making min even. This ensures efficiency because we know that odd and even numbers in a range will alternate, so there's no need to check every number, we simply start with the first even number, which is either min itself, or min+1. Depending on which closed range you actually meant, we can call this function as follows: print_evens (1,100); // means [1,99] print_evens (1, 101); // means [1,100] print_evens (2, 100); // means [2,99] print_evens (2, 101); // means [2,100]
You write a for loop. Either increment the variable by 2 at a time, or increment it by 1 at a time, but inside the loop, test whether the number is divisible by 2.
for(int i = 1; i < 100; i+=2) {
System.out.println(i);
}
You can always write it out by hand...
int i = 1;
printf("%d\n", (i++));
printf("%d\n", (i++));
printf("%d\n", (i++));
...copy-paste 97 more times...
for(int i = 0; i <= 100; ++i) {
System.out.println(i);
}
Pseudocode:
for (int i = 8; i < 100; i = i + 2)
{
print("The value is ", i + 2);
}
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
In visual basic: Module Module1 Sub Main() Dim Inst As Integer For Inst = 0 To 100 Step 2 Console.WriteLine(Inst) Next End Sub End Module
You need a code that can run to print even numbers between 10 and 100 using the qbasic command.
system.out.println(" print 1-100 numbers");for(i=0;i
CLS PRINT "PROGRAM: Print squares of all even numbers from 1 to 20" PRINT PRINT "number", "squared" PRINT FOR number% = 1 TO 20 IF number% MOD 2 = 0 THEN PRINT number%, number% * number% END IF NEXT END
Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.
Use a counted loop in the closed range [1:100]. If the count is in the closed range [40:50], print the number. For all other numbers outwith this range, only print the number if it is prime.
This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.
The prime numbers before 100 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, and 97. To print these prime numbers, simply cut and paste this list into your computer word processor and print it like any other document.
The prime numbers (factors) of 100 are: 2 and 5
25 percent of the numbers from 1 to 100 are prime numbers.
what are prime numbers higher than 100
The prime numbers of 100 are: 2, 2, 5 and 5
100
The three prime numbers after 100 are: 101 103 107
There are 25 prime numbers less than 100
There are 25 prime numbers between 1 and 100.