answersLogoWhite

0

#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

10y ago

Still curious? Ask our experts.

Chat with our AI personalities

JudyJudy
Simplicity is my specialty.
Chat with Judy
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
More answers

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

User Avatar

Wiki User

11y ago
User Avatar

public class Test {

public static void main(String args[]){

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

System.out.println(i);

}

}

}

User Avatar

Wiki User

16y ago
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