Shell Script to print odd and even numbers Last Updated : 31 Jul, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to print even and odd numbers. We will take a number as input and print all even and odd numbers from 1 to the number. Input : Enter the Number - 10 Output : Even Numbers - 2, 4, 6, 8, 10 & Odd Numbers - 1, 3, 5, 7, 9 Input : Enter the Number - 5 Output : Even Numbers - 2, 4 & Odd Numbers - 1, 3, 5 The approach is that we will divide it in 2. If the remainder is zero, it is an even number, else it is an odd number. Explaining the code: Taking input from the user, and loop till we reach the number while [ $i -le $n ] - Here "-le" is a comparison operator indicating less than or equal to. Then we will check whether it is divisible by 2.`expr $i % 2` here "expr" is used to do arithmetic operations and is used with back tick(~) If the loop is used to check if the remainder is equal to zero, if true it will print an even number, fi indicate the end of if loop.A similar process is for odd numbers.Code: # Take user inputecho "Enter a number"read necho "Even Numbers - "i=1# -le means less than or equal towhile [ $i -le $n ] do# arithmetic operations is performed with 'expr' rs=`expr $i % 2`if [ $rs == 0 ]thenecho " $i" # end of if loopfi# incrementing i by one((++i)) # end of while loop done# Now printing odd numbersecho "Odd Numbers - "i=1 while [ $i -le $n ]do rs=`expr $i % 2`if [ $rs != 0 ]thenecho " $i" fi((++i))doneOutput: Comment More infoAdvertise with us Next Article Shell Script to print odd and even numbers C codeutin Follow Improve Article Tags : Linux-Unix Shell Script Similar Reads Shell Script to Display the Digits which are in Odd Position Here given a list of numbers, our task is to find the odd position from the given number. Example: Input: 123456 Output: 135 Explanation: 1, 2, 3 are at odd position. Input: 34567 Output: 357 Explanation: 3, 5, 7 are at odd position. We will have to input a number from the user for a dynamic script. 2 min read Check if a Number is Odd or Even in R Programming In R programming, it is often necessary to determine whether a given number is odd or even. An odd number is one that cannot be evenly divided by 2, whereas an even number is divisible by 2 without any remainder. This determination is useful in various scenarios, such as in decision-making processes 2 min read Print "Even" or "Odd" without using conditional statement Write a program that accepts a number from the user and prints "Even" if the entered number is even and prints "Odd" if the number is odd. You are not allowed to use any comparison (==, <,>,...etc) or conditional statements (if, else, switch, ternary operator,. Etc). Method 1 Below is a tricky 4 min read PHP check if a number is Even or Odd Checking if a number is even or odd involves determining whether the number is divisible by 2. An even number has no remainder when divided by 2, while an odd number has a remainder of 1. This can be done using various methods like modulo or bit manipulation.Examples :Input : 42 Output : Even Explan 3 min read TCS Coding Practice Question | Check Odd or Even Given a number, the task is to check if this number is Odd or Even using Command Line Arguments. A number is called even if the number is divisible by 2 and is called odd if it is not divisible by 2. Â Examples:Input: 123Output: NoInput: 588Output: YesApproach:Since the number is entered as Command l 4 min read Like