C Program to Print First 10 Odd Natural Numbers

Write a C program to print first 10 odd natural numbers using for loop.

#include <stdio.h>

int main()
{
	printf("The First 10 Odd Natural Numbers are\n");

	for (int i = 1; i <= 10; i++)
	{
		printf("%d\n", 2 * i - 1);
	}
}
C Program to Print First 10 Odd Natural Numbers

This C program displays the first 10 odd natural numbers using a while loop.

#include <stdio.h>

int main()
{
	int i = 1;

	printf("The First 10 Odd Natural Numbers are\n");

	while (i <= 10)
	{
		printf("%d\n", 2 * i - 1);
		i++;
	}
}
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19

This C example uses the do while loop to print the first 10 odd natural numbers.

#include <stdio.h>

int main()
{
	int i = 1;

	printf("The First 10 Odd Natural Numbers are\n");

	do
	{
		printf("%d\n", 2 * i - 1);

	} while (++i <= 10);
}
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.