(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Program to print all natural numbers from 1 to n. - TecGlance

Header Ads

Program to print all natural numbers from 1 to n.

Algorithm:
Step 1: Start
Step 2: Assign i=1
Step 3: Read a number, num
Step 4: Repeat step 5&6 until i=num reach
Step 5: Print i
Step 6: Compute i=i+1
Step 7: Stop

Flowchart:

Program code:
i=1
num=int(input('Enter a number '))
while i<=num:
    print i,
    i=i+1

2 comments:

  1. Write a C program to print all natural numbers from 1 to n using for loop.

    Code of given problem:

    int main()
    {
    int i=1,n;
    printf("Enter the number to print all natural number till that entered number\t");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    printf("%d\t",i);
    }
    return 0;
    }

    Very informative blog!

    Please take some time to visit my blog @
    for loop program examples

    Thanks!

    ReplyDelete
  2. good boy malan

    ReplyDelete

Powered by Blogger.