Header Ads Widget

Mathematical Calculations: Odd Numbers | iMocha coding questions

Mathematical Calculations: Odd Numbers

Write a program to print the odd numbers from the list.

The list terminates when -1 is encountered.

Note

Odd Number: A number that is not divisible by 2

Function Description

In the provided code snippet, implement the logic using the variables to print the odd numbers from the list, one per line. You can write your code in the space below the phrase "WRITE YOUR DOGIC HERE".

There will be multiple test cases running so the input and Output should match exactly as provided. The base output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables.

Input Format

The list of numbers in integer format, one per line.

Sample input:

1
4
3
6
8
9
-1

Output format

The output contains integers that print odd numbers from the list, one per line

Sample output:

1
3
9

Explanation

As 1, 3, and 9 are not divisible by 2, they are odd numbers.

Hence, the output is 

1
3
9

C++ code:-

#include <iostream>
using namespace std;

int main() {
int n;
  while(1)
{
cin>>n;
if(n==-1)
break;
if(n%2!=0)
cout<<n<<endl;
}
  return 0;
}

Wipro :-

Infytq :-

Key Points;-

Hackerrank:-


C-tutorial:-

See more:-




Post a Comment

0 Comments