Open In App

Program to print all two-digit numbers in descending order

Last Updated : 20 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Write a program to print all the two-digit numbers in descending order, that is print all the two-digit numbers from largest to smallest.

Output format:

99 98 97 96 95 94 93 ….. 13 12 11 10

Approach:

We know that the largest two-digit number is 99 and the smallest two-digit number is 10. So, we can start from 99 and then keep on decreasing the number and print till we reach 10.

Step-by-step algorithm:

  • Declare a for loop which start from 99 and keep on decreasing the number by 1 till we reach 10.
  • For each iteration, print the number.
  • After all the iterations, we will have all the two-digit numbers printed in decreasing order.

Below is the implementation of the above approach:

C++




#include <iostream>
using namespace std;
 
int main() {
 
    for(int number = 99; number >= 10; number --) {
        cout << number << " ";
    }
    return 0;
}


Java




public class Main {
    public static void main(String[] args) {
        // Iterate from 99 to 10 in reverse order
        for (int number = 99; number >= 10; number--) {
            // Print the current number followed by a space
            System.out.print(number + " ");
        }
    }
}


Python3




# Iterate from 99 down to 10 (inclusive)
for number in range(99, 9, -1):
    # Print the current number followed by a space
    print(number, end=" ")
 
# Add a newline after printing all numbers
print()


C#




using System;
 
class Program
{
    static void Main()
    {
        // Loop from 99 to 10 in decreasing order
        for (int number = 99; number >= 10; number--)
        {
            Console.Write(number + " ");
        }
 
        // Ensure a newline after printing the numbers
        Console.WriteLine();
    }
}


Javascript




for (let number = 99; number >= 10; number--) {
    console.log(number + " ");
}
//this code is contribited by Prachi


Output

99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...





Time Complexity: O(1)
Auxiliary Space: O(1)



Similar Reads

Program to print all three digit numbers in ascending order
Write a program to print all the three-digit numbers in ascending order. Output Format: 100 101 102...till 999 Approach: Using for Loop to print all the three Digit Numbers: Use for loop to iterate from the smallest three-digit number, that is 100 till we reach the largest three-digit number, that is 999 and, in every iteration, print the number. A
3 min read
Program to generate a random two-digit number
Write a program to generate a random two-digit number. Example 1: 73Example 2: 26 Approach: To solve the problem, follow the below idea: We can generate a random two-digit number by generating a random integer first and then modulo it by 90. Now, after modulo 90 the remainder can be in the range 0 to 89, so in order to have the remainder as a two-d
2 min read
Program to print first 10 even numbers
Program to print first 10 even numbers. A number is even if it is divisible by 2 for example 4, 100, 24 etc. Output Format: 0 2 4 6 8 10 12 14 16 18 Approach: Checking Parity using Modulo operator(%) Using the modulo % operator we can find the remainder of any number when divided by 2, giving us the parity according to two cases: remainder = 0: Eve
3 min read
Program to print first 10 prime numbers
Write a program to print the first 10 prime numbers.Note: A number N is said to be prime if it has exactly two factors i.e. 1 and the number itself N Output Format: 2, 3, 5, 7, 9... Approach: Prime Test: To check whether a number N is prime we can check its divisibility with each number from 2 to N - 1, If it is divisible by any number in this rang
4 min read
Program to print numbers having remainder 3 when divided by 11
Write a program to print all numbers from 1 to 1000 which leave a remainder of 3 when divided by 11. Output format: 3, 14, 25, 36, 47.... 993 Approach: To solve the problem, follow the below idea: The problem can be solved by simply using for loop and iterate from 3 up to the 1000 and increment by 11 as we are dividing by 11. Step-by-step approach:
4 min read
Program to print first 10 numbers of Fibonacci series
Find the first 10 numbers of Fibonacci series. The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1. The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ........ Approach: To solve the problem, follow the below idea: We can take two variable
3 min read
Program to print all multiples of 7 till 1000
Write a program to print all multiples of 7 till 1000. Output Format: 7, 14, 21, 28, 35 ..... 994 Approach: To solve the problem, follow the below idea: The approach of this program is to run a loop starting from 7 and in each iteration add 7 to the current multiple to get the next multiple. Step-by-step algorithm: This program uses a for loop to i
3 min read
Program to generate a random single digit number
Write a program to generate a random single-digit number. Example 1: 7Example 2: 3 Approach: To solve the problem, follow the below idea: To generate a random single-digit number, we can first generate a random integer and then take apply modulo to get the last digit of that random integer. This last digit can be the random single digit number. Ste
2 min read
Program to generate a random three digit even number
Write a program to generate a random three-digit even number. Examples: Example 1: 482Example 2: 736 Approach: To solve the problem, follow the below idea: We can generate a random three-digit number by generating a random integer first and then modulo it by 900. Now, after modulo with 900, the remainder can be in the range 0 to 899, so in order to
3 min read
Program to find the sum and difference of two numbers
Given two Integers A and B, your task is to find the sum and difference of two numbers. Examples: Input: A = 4, B = 9Output: Sum = 13 and Difference = -5Input: A = -3, B = -2Output: Sum = -5 and Difference = -1 Approach: The problem can be solved using arithmetic operators. Operations on Numbers: Addition (+): This operation is used to add the inpu
3 min read
Article Tags :