display the first n natural numbers

+2 votes
asked Oct 10 by (140 points)

7 Answers

0 votes
answered Oct 11 by (340 points)
#include<stdio.h>

int main()

{

int i;

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

{

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

}

}
commented Oct 11 by (340 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 by (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 by (270 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 by (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 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 by (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 by (1,070 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 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.
...