Header Ads Widget

Write a program to print first N natural numbers in C. (N is given by user)

Write a program to print first N natural numbers in C. (N is given by user) 

Given a number n , write a program to print the first n natural numbers . Value of n is given by user .

Sample input:

10

Sample output:

 List of Natural Numbers from 1 to 10 are 
 1  2  3  4  5  6  7  8  9  10

Write a program to print first N natural numbers in C. (N is given by user) 

The objective of the code is to print the first n natural number . n is given by the user .

Code(C):-

#include<stdio.h>
int main()
{
int n, i;
printf("\n Please Enter any Integer Value : ");
scanf("%d", &n);
printf("\n List of Natural Numbers from 1 to %d are \n", n);
for(i=1;i<=n;i++)
{
printf(" %d ",i);
}
return(0);
}

Output:-
Please Enter any Integer Value : 10
List of Natural Numbers from 1 to 10 are
1   2   3   4   5   6   7   8   9   10



Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-