Print first 10 natural numbers using while loop in C
In this post, you will learn how to print the first 10 natural numbers using a while loop in the C programming language. Such a type of logical question is generally asked in an interview or in competitive exams. This can be helpful to improve your logical programming skills and other logical application development.
Print numbers from 1 to 10 using while loop
In the given example, first we initialise a variable input with 1 and iterate over the loop until the number is less than or equal to 10. Then we print the value of the input.
// C Program to Print First 10 Natural Numbers
// Using While Loop
#include <stdio.h>
int main(){
int i = 1;
printf("The first 10 natural numbers are: \n");
while (i <= 10){
printf("%d \n", i);
i++;
}
return 0;
}
Output of the above code:
The first 10 natural numbers are:
1
2
3
4
5
6
7
8
9
10
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to find area of rectangle
C program to convert celsius to fahrenheit
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to calculate compound interest
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative