answersLogoWhite

0


Best Answer

Two solutions immediately spring to mind:

  1. Run over all the numbers in the range and if the number is even print it;
  2. run over the numbers starting with the first even number in the range using a step of 2 (so that only even numbers are considered) and print the numbers.
User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

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/>");

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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 );

}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

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]

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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.


This answer is:
User Avatar

User Avatar

Wiki User

15y ago

for(int i = 1; i < 100; i+=2) {

System.out.println(i);

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

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...

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

for(int i = 0; i <= 100; ++i) {

System.out.println(i);

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Pseudocode:

for (int i = 8; i < 100; i = i + 2)

{

print("The value is ", i + 2);

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you print prime numbers in basic from 1 to 100?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Program for print prime all number from 1 to 100 in foxpro?

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.


How can print prime numbers in between 1-100 but not adjust 40-50 in php language?

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.


Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.


How do you print all prime numbers before 100?

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.


Which are prime numbers in 100?

The prime numbers (factors) of 100 are: 2 and 5


What percent of numbers from 1 to 100 are prime numbers?

25 percent of the numbers from 1 to 100 are prime numbers.


What are prime numbers higher than 100?

what are prime numbers higher than 100


What are the prime numbers if 100?

The prime numbers of 100 are: 2, 2, 5 and 5


How many prime numbers are between 0-100?

100


What are the 3 prime numbers after 100?

The three prime numbers after 100 are: 101 103 107


How many prime numbers are less then 100?

There are 25 prime numbers less than 100


How many prime numbers in 1-100?

There are 25 prime numbers between 1 and 100.