Computer Science, asked by unknown6766654, 2 months ago

Write a program to print natural odd numbers less than hundred using while loop.​

Answers

Answered by viji18net
0

Answer:

Input:

   Enter value of N: 10

  Output:

   ODD Numbers from 1 to 10:

   1 3 5 7 9

Logic:

There are two variables declared in the program 1) number as a loop counter and 2) n to store the limit.

Reading value of n by the user.

Initialising loop counter (number) by 1 as initial value number =1

Using while loop by checking the condition number<=n (value of number is less than or equal to n) - this will execute the loop until the value of number is less than or equal to n.

Then, within the loop, we are checking the condition to check whether number is ODD or not, the condition is (number%2 != 0) - it returns true if number is not divisible by 2.

Similar questions