answersLogoWhite

0


Best Answer

#include<iostream>

unsigned print_naturals (unsigned max)

{

unsigned num = 0;

while (num<max)

std::cout << ++num << ' ';

std::cout << std::endl;

}

int main()

{

// print first 10 natural numbers:

print_naturals (10);

// print first 100 natural numbers:

print_naturals (100);

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

Here's a program that ask for a number and then prints the list of numbers and their running sum:

main

SUB main

INPUT "What is the final number"; final

j = 0

PRINT " Number", " Running Count"

FOR i = 1 TO final

j = i + j

PRINT STR$(i), j

NEXT i

END SUB

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

public class Test {

public static void main(String args[]){

for(int i = 0; i < 1000; i++){

System.out.println(i);

}

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A java program to print natural numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


What is java program on computers?

#!/usr/bin/perl print 'java program';


How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.


Write in BlueJ to print lucky numbers?

To print lucky numbers in java, you must give the following program: class example { static public void main(String[] args) { System.out.println("Lucky number is your favourite number which is your DOB"); } }


Write a program to Print pyramid of numbers using java?

hi question is here, 1 1 2 1 2 3 1 2 3 4


What is java console?

The Java console is a display of output sent by a Java program. This is similar to the MS DOS operating system.To print to the console, a programmer will type "println(text);" or "print(text);" depending is the programmer wants to make a new line after the text(println) or not(print).


Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).


What Program that will display the even numbers in data structures and algorithms?

JAVA


How do you compile and execute a java program which finds out the highest of any five numbers?

it will be destroyed.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


How do you construct a java program that print table with backslash?

within inverted commas using two backslashes consequently .. we will print the backslash. ex: printf("//n it will gives output");


What does it mean to generate random numbers in Java?

Generating random numbers in Java is somewhat of a misnomer because the numbers are actually semi-random.It means to use the program to obtain random integers to use in hypothetical situations such as statistics.