#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=50;i+=2)
{
printf("\t %d", i);
}
getch();
}
wap that displays even numbers from 2 to 50 .
unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);
I can't imagine a useful reason to have a recursive function to find this, but here you go: int sumEvens(int start, int end) { // end condition if (start > end) { return 0; } // correction if we start on an odd number if (start % 2 == 1) { return sumEvens(start + 1, end); } // actual work return start + sumEvens(start + 2, end); } Invoke with sumEvens(2, 50) to get the sum of all even numbers in the range [2,50]
That's entirely up to the programmer. A program could create 0 files or 50 million files (or any number in between).
It is actually quite easy to write a program in java to do this. The easiest way to do this that I can think of is to use the remainder operator (%) to test whether a number is odd or not. Here is a simple program that will print out all the odd numbers between 1 and 50. public class OddNumbers { public static void main(String[] args) { int i=1; while(i < 50) { if(i%2 != 0) { System.out.println(i); } i++; } } }
echo enter n value read n sumodd=0 sumeven=0 i=0 while [ $i -ne $n ] do echo "Enter Number" read num if [ `expr $num % 2` -ne 0 ] then sumodd=`expr $sumodd + $num` sumeven=`expr $sumeven+$num` fi i=`expr $i + 1` done echo Sum of odd numbers = $sumodd echo Sum of even numbers = $sumeven
2,3,5,7,9,11,13,17,19,23,29,31,37,39,41,43,47,49
(rand()&50+1)*2
You can use int i; for (i = 10; i <= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.
Generate a random number in half the range you are interested in. If generating odd values, subtract 1 from the upper bound of the range. That is, if the range is 0 to 100, then generate a random number in the range 0 to 50 for even numbers and 0 to 49 for odd numbers. Double the generated number to obtain the even value, or double it and add 1 to obtain the odd value.
I don't believe that 50 perfect numbers have ever been found, last time I checked there were only about 47 known perfect numbers. It would also require an extremely powerful computer.
Even numbers account for 50% of the numbers from 1 to 50.
There are several shell programs available for download on the Internet that will generate prime numbers. The best way to find a prime number is through calculation, however.
Here is a simple program that will list all the even numbers between 1 and 50: public class EvenNumbers { public static void main(String[] args) { for(int i=1; i<=50; i++) { if(i%2 ==0) { System.out.println(i); } } } }
The ratio of odd numbers to even numbers is 1 : 1 or 50-50.
The sum of the first 50 even numbers is 2,550.
All even numbers between 50 and 80 are composite.
The even numbers of 150 are: 2,6,10,30,and 50