Algorithm


Problem Name: beecrowd | 1070
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1070

Six Odd Numbers

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read an integer value X and print the 6 consecutive odd numbers from X, a value per line, including X if it is the case.

Input

The input will be a positive integer value.

Output

The output will be a sequence of six odd numbers.

Input Sample Output Sample

8

9
11
13
15
17
19

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
int main(){

    int i, X, howManyOdd = 6;
    scanf("%d", &X);
    for( i = X; i  <  (X+(howManyOdd*2)) ; i+=2) {
        int odd;
        if(i % 2 == 0) {
            odd = i + 1;
            printf("%dn", odd);
        } else {
            odd = i;
            printf("%dn", odd);
        }
    }
    return 0;
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
8

Output

x
+
cmd
9 11 13 15 17 19

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main()
{
    int x, tmp = 0;
    bool ver = false;
    
    cin >> x;
    
    while(ver == false)
    {
        if(x % 2 == 1) {
            cout << x << endl;
            tmp++;
        }
        
        if(tmp == 6)
        return 0;
        
        x++;
    }
    
    return 0;
}  
Copy The Code & Try With Live Editor

Input

x
+
cmd
8

Output

x
+
cmd
9 11 13 15 17 19

#3 Code Example with Java Programming

Code - Java Programming


import java.util.*;

public class Main {
    public static void main(String args[]) {
        int i, X, howManyOdd = 6;
        Scanner input = new Scanner(System.in);
        X = input.nextInt();
        for( i = X; i  <  (X+(howManyOdd*2)) ; i+=2) {
            int odd;
            if(i % 2 == 0) {
                odd = i + 1;
                System.out.printf("%dn", odd);
            } else {
                odd = i;
                System.out.printf("%dn", odd);
            }
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
8

Output

x
+
cmd
9 11 13 15 17 19

#4 Code Example with Python Programming

Code - Python Programming


n=int(input())
i=0
while(i<6):
    if(n%2!=0):
        print(n)
        i=i+1
    n=n+1
Copy The Code & Try With Live Editor

Input

x
+
cmd
8

Output

x
+
cmd
9 11 13 15 17 19
Advertisements

Demonstration


Previous
#1069 Beecrowd Online Judge Solution 1069 Diamonds and Sand - Solution in C, C++, Java, Python and C#
Next
#1071 Beecrowd Online Judge Solution 1071 Sum of Consecutive Odd Numbers I - Solution in C, C++, Java, Python and C#