Write a program in C to display the first 10 natural numbers.

Example 1.Write a program in C to display the first 10 natural numbers.

#include<stdio.h>

void main ()
{
int i,n;
scanf("%d",&n);
printf("The first 10 natural numbers are: ",n);

for(int i=1; i<=n;i++)
{

printf("%d ",i);
}

}

When you run this code, it will output the numbers 1 through 10 separated by spaces. The loop will start with i = 1 and print it to the console. Then, it will increment i by 1 and repeat the process until i reaches 11, which violates the condition i <= 10 and terminates the loop.

OUTPUT:

The first 10 natural numbers are:
1 2 3 4 5 6 7 8 9 10

C++ Beginners Problems

QUORA

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck