Home » C programs » C looping programs

C program to print numbers from 1 to 10 using while loop



This is an example of while loop in C programming language - In this C program, we are going to print numbers from 1 to 10 using while loop.
Submitted by IncludeHelp, on March 07, 2018

Using while loop, in this C program we are going to print the numbers from 1 to 10.

To print the numbers from 1 to 10,

  • We will declare a variable for loop counter (number).
  • We will check the condition whether loop counter is less than or equal to 10, if condition is true numbers will be printed.
  • If condition is false – loop will be terminated.

Program to print numbers from 1 to 10 using while loop in C

#include <stdio.h>

int main()
{ 

	//loop counter declaration
	int number;
	
	//assign initial value 
	//from where we want to print the numbers
	number =1;
	
	//print statement
	printf("Numbers from 1 to 10: \n");
	
	//while loop, that will print numbers 
	//from 1 to 10
	while(number<=10)
	{
		//printing the numbers
		printf("%d ",number);
		//increasing loop counter by 1
		number++;
	}
	
	return 0;
}

Output

Numbers from 1 to 10: 
1 2 3 4 5 6 7 8 9 10 





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.




Comments and Discussions





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.