Ex: Write a C program to print natural number series. How to write a C program to print natural number series. C program to print natural number series.
Input from user:
Enter the number: 8
Expected output:
1 2 3 4 5 6 7 8...
You can explore more number series examples from 👉 Here.
Step by Step logic of the given program:
1. Accept input number from user declare variable say no.
2. Run for loop from 1 to no to print series from 1 to n:
3. Inside that loop print value of i.
Program to print natural numbers series :
#include<stdio.h>
void main()
{
int no;
int i;
printf("Enter the number:\n");
scanf("%d",&no);
/*Run loop from 1 to no*/
for(i=1;i<=no;i++)
{
/*Print value of i with one space*/
printf("%d ",i);
}
}
Above program shows the following output:
Share your thoughts in the comments below...
No comments:
Post a Comment
If you have any doubts, please discuss here...👇