Write a program to print the first ten natural numbers .(use forNEXT)
Answers
Answer:
#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");
}
Answer:
python -->
print("here are the first ten natural numbers ==>\n")
i = 0
while (i < 10):
i += 1
print(i)
c -->
//compiled on gcc linux 5.12
//to compile it on linux type gcc program.c -o program_naturalnum
#include <stdio.h>
int main()
{
printf("natural numbers from 1 to 10\n");
int i;
for (i = 1; i < 11; i++){
printf("%d\n", i);
}
return 0;
}
java -->
//Main.java
public class Main {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
System.out.println(i);
}
}
}
c++ -->
#include <iostream>
int main()
{
std::cout << "natural numbers from 1 to 10\n" << std::endl;
int i;
for (i = 1; i < 11; i++){
std::cout << i << std::endl;
}
return 0;
}
fortran -->
program NatNUM
integer i
do i = 0, 9
j = i+1
print*, j
end do
end program NatNUM
cobol ->
PROGRAM-ID. NATNUM.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 Ind PIC 9(1) VALUE 0.
PERFORM DIVISON.
PERFORM OutputData WITH TEST AFTER UNTIL Ind > 10
GO TO ForLoop
OutputData.
DISPLAY Ind.
ADD 1 TO Ind.
ForLoop.
PERFORM OutputData2 VARYING Ind FROM 1 BY
1 UNTIL Ind = 10
STOP RUN.
OutputData2.
DISPLAY Ind.