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