Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

display the first n natural numbers

+2 votes
asked Oct 10, 2019 by Shaurya Deep (140 points)

7 Answers

0 votes
answered Oct 11, 2019 by Harsha (380 points)
#include<stdio.h>

int main()

{

int i;

for(i=1;i<i+1;i++)

{

printf("%d\n",i);

}

}
commented Oct 11, 2019 by Harsha (380 points)
if you want first 10 natural numbers put 11 in place of   i+1


have any doubts message me insta id(gutsboy_harsha)
commented Oct 27, 2019 by Molero Raffi (540 points)
You could have just done this:

    int i = 0;
    while (1) printf("%i\n", ++i);

and just replaced "true" with "i <= n" where n is the last natural number to print
0 votes
answered Oct 12, 2019 by saiteja (290 points)
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        printf("%d\t",i);
    }
}
0 votes
answered Oct 14, 2019 by karthik srinivas (190 points)
#include<stdio.h>

void main()

{

int i,x;

printf("Enter the n value");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

printf("%d, ",i);

}

getch();

}
0 votes
answered Oct 16, 2019 by G Abhijit
#include<stdio.h>

void main()

{

int i,n=0;

printf("Enter the value of n = ");

scanf("%d",&n);

for(i=1;i<=n-1;i++)

{

printf("%d, ",i);

}
printf("%d.",n);
}
0 votes
answered Oct 22, 2019 by santoshverma (140 points)
void main()

{

int n;

cout<<"enter the number till you want the natural number to get printed";

cin>>n;

for(int i=0;i<n-1;i++)

{

cout<<" natural numbers are";

cout<<i;

}

}
0 votes
answered Nov 7, 2019 by dheeraj (1,090 points)
a=int(input('enter upto u want natural numbers '))
for i in range(1,a+1):
    print(i,end=' ')
 

output:                                                      @python

enter upto u want natural numbers 100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
0 votes
answered Nov 9, 2019 by anonymous
#include<stdio.h>

void main()

{

int n;int i;

for(i=0;i<=n;i++)

{

printf("%d\n",i);

}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...