<\/span><\/h2>\n\n\n\n int i = 1, N;\n<\/pre>\n\n\n\nIn the first line of the program, we have declared two variables i<\/code> and N<\/code>. We have assigned a value of 1 to i<\/code> variable.<\/p>\n\n\n\n \/\/ Asking for input\n printf(\"Enter the value of N: \");\n scanf(\"%d\", &N);\n<\/pre>\n\n\n\nThen, we take input from the user using the scanf()<\/code> function. The scanf()<\/code> function is used to read input from the input. Here, the user is asked to enter the upper limit up to which the user wants to print the numbers. The entered number gets stored in the N<\/code> variable.<\/p>\n\n\n\n \/\/ Printing all natural numbers from 1 to N\n while (i <= N)\n {\n printf(\"%d\\n\", i);\n i++;\n }\n<\/pre>\n\n\n\nAfter that, we defined a while loop which checks whether the value of i<\/code> is less than or equal to N<\/code> or not, if it is less than N<\/code>, then this loop is executed, and it prints the value of i<\/code> and then increments the value of i. This loop keeps on iterating until the value of i<\/code> is greater than the value of N<\/code>.<\/p>\n\n\n\n<\/span>Conclusion<\/strong><\/span><\/h2>\n\n\n\nI hope you all understand how to print all natural numbers from 1 to N using a While loop in the C programming language.<\/p>\n\n\n\n
You can also use the same logic to print the natural numbers in the for loop and do-while loop approach.<\/p>\n","protected":false},"excerpt":{"rendered":"
Hey coders, today you will learn how to print all natural numbers from 1 to N using a While loop.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[294],"tags":[209],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts\/9635"}],"collection":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/comments?post=9635"}],"version-history":[{"count":10,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts\/9635\/revisions"}],"predecessor-version":[{"id":9651,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/posts\/9635\/revisions\/9651"}],"wp:attachment":[{"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/media?parent=9635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/categories?post=9635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingbroz.com\/wp-json\/wp\/v2\/tags?post=9635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}