Write a C program to print all natural numbers from 1 to n

Introduction

Write a C program to print all natural numbers from 1 to n

#include <stdio.h>

int main()
{
    int i, num;
    //Reading number
    printf("Enter any number: ");
    scanf("%d", &num);

    printf("Natural numbers from 1 to %d \n", num);

    /* Starting loop from i=1 & priting value of i
     to get natural numbers */
    for(i = 1; i <= num; i++)
    {
        printf("%d\n", i);
    }

    return 0;
}

Result

Leave a Comment