Editorial
Read the elements of the sequence one by one using a loop and immediately print the odd ones. A number is considered odd if . However, the condition is incorrect for checking the oddness of negative values of . In the C language, dividing a negative odd number by results in .
Algorithm implementation — loop
Read the number of input values .
scanf("%d",&n);
Process the numbers sequentially in a loop.
for(i = 0; i < n; i++) { scanf("%d",&val);
If the number is odd, print it.
//if (val % 2 == 1 || val % 2 == -1) printf("%d ",val); if (val % 2 != 0) printf("%d ",val); }
Algorithm implementation — array
Declare an array.
int m[101];
Read the input sequence of integers into the array .
scanf("%d",&n); for (i = 0; i < n; i++) scanf("%d", &m[i]);
Iterate through the numbers in the array. If is odd, print it.
for (i = 0; i < n; i++) if (m[i] % 2 != 0) printf("%d ", m[i]); printf("\n");
Java implementation
import java.util.*; class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in);
Read the number of input values .
int n = con.nextInt();
Read the input sequence of integers.
for(int i = 0; i < n; i++) { int val = con.nextInt();
If the number is odd, print it.
if (val % 2 != 0) System.out.print(val + " "); } System.out.println(); con.close(); } }
Python implementation
Read the input sequence of integers into the list .
n = int(input()) lst = list(map(int,input().split()))
Process the numbers in the list using a loop.
for x in lst:
If the number is odd, print it.
if x % 2 != 0: print(x, end = " ")
Python implementation — list
Read the input sequence of integers into the list .
n = int(input()) lst = list(map(int,input().split()))
Process the numbers in the list using a loop.
for i in range(n):
If the number is odd, print it.
if lst[i] % 2 != 0: print(lst[i],end = " ")