Programming contest 4

in #contest6 years ago

Introduction to contest

This contest is to just brainstorm or practice your programming knowledge. The prize is not much but a suitable answer will definitely get the prize.

Rules

Failed to follow the rules leads to disqualification

Question

Print odd numbers from 1-1000.

The programming language to use

Python/C/C++

Prize

100% sbd gained from this post.

Note: If there is more than 5 winner in the comment section then all the correct answer will be assigned a number from 1 to n and using programming script of python one number will be generated and is declared as winner, pretty like programming luck draw else reward will be shared.

Also, Resteem this post and get 0.05 SBD from me if you have more than 1000 followers and 0.01 for less than 1000 followers.

Just post your profile link with which you resteemed and write resteemed

Example: Resteemed - your link

The contest will be organized frequently.

Follow @programminghub for more

Thank You

Sort:  

Shorter solution in python:

for i in range(1, 1000, 2):
      print(i)

Explanation: range function can take 3 arguments:
[start], stop[, step]
So to print odd numbers starting from 1, you can just use a step size of 2 instead of skipping them later using if i % 2

Hello!
Here's my solution in python:

for i in range(1, 1000):
if i % 2 == 1: print(i)

C++

for(int i = 1; i < 1000; i = i + 2)
{
std::cout << i << std::endl;
}

#include <iostream>

int main()
{
 for (int i = 1; i < 1000; i += 2)
  std::cout << i << std::endl;
 return 0;
}

All rewards has been sent.. closed

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.029
BTC 60723.46
ETH 3353.68
USDT 1.00
SBD 2.51