Here, we have a basic program example to display first 10 natural numbers using different languages. This program is created in c language, c++, Java, and Python.
Code to display natural numbers in C language
#include <stdio.h>
void main()
{
int i;
printf("The first 10 natural numbers are:\n");
for (i=1;i<=10;i++)
{
printf("%d ",i);
}
printf("\n");
}
Code to display natural numbers in C++ language
#include<iostream>
using namespace std;
int main()
{
int i;
cout<<"The first 10 natural numbers are:\n";
for (i=1;i<=10;i++)
{
cout<<i<<endl;
}
}
Code to display natural numbers in Python language
print("The first 10 natural numbers are: \n")
for i in range(1, 11):
print(i)
Code to display natural numbers in Java language
import java.util.*;
public class naturalNo {
public static void main(String[] args) {
int i;
System.out.println("The first 10 natural numbers are:");
for (i=1;i<=10;i++)
{
System.out.println(i);
}
System.out.println("\n");
}
}