Algorithm
Six Odd Numbers
Adapted by Neilor Tonin, URI Brazil
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 |
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
Output
#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
Output
#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
Output
#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
Output