Write a program to Print First n Numbers in Reverse Order using While loop in C
Write a program to Print First n Numbers in Reverse Order using While loop in C++
Write a program to Print First n Numbers in Reverse Order using While loop in Python
Write a program to Print First n Numbers in Reverse Order using While loop in PHP
Write a program to Print First n Numbers in Reverse Order using While loop in Java
Write a program to Print First n Numbers in Reverse Order using While loop in Java Script
Write a program to Print First n Numbers in Reverse Order using While loop in C#
Explanation:
Logic
Take input for n (the number of terms to print).
Use a While loop to iterate from n down to 1.
Print each number during the iteration.
Print First n Numbers in Reverse Order using While loop
C
C++
Python
PHP
JAVA
Java Script
C#
#include <stdio.h>
int main() {
int n;
printf("Enter the value of n: ");
scanf("%d", &n);
while (n > 0) {
printf("%d ", n);
n--;
}
printf("\n");
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the value of n: ";
cin >> n;
while (n > 0) {
cout << n << " ";
n--;
}
cout << endl;
return 0;
}
n = int(input("Enter the value of n: "))
while n > 0:
print(n, end=" ")
n -= 1
print()
<?php
$n = (int)readline("Enter the value of n: ");
while ($n > 0) {
echo $n . " ";
$n--;
}
echo "\n";
?>
import java.util.Scanner;
public class ReverseOrder {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = sc.nextInt();
while (n > 0) {
System.out.print(n + " ");
n--;
}
System.out.println();
sc.close();
}
}
let n = parseInt(prompt("Enter the value of n: "));
while (n > 0) {
console.log(n);
n--;
}
using System;
class Program {
static void Main() {
Console.Write("Enter the value of n: ");
int n = int.Parse(Console.ReadLine());
while (n > 0) {
Console.Write(n + " ");
n--;
}
Console.WriteLine();
}
}