C Program to Print First N Odd Natural Numbers

C Program to Print First N Odd Natural Numbers

C program to print first n odd natural numbers; Through this tutorial, we will learn how to print first n (10, 100, 1000 .. N) odd natural numbers in the c program with the help for loop, while and loop.

C Programs to Print First N Odd Natural Numbers

  • Algorithm to Print First N Odd Natural Numbers
  • C Program to Print First N Odd Natural Numbers using For Loop
  • C Program to Print First N Odd Natural Numbers using While Loop

Algorithm to Print First N Odd Natural Numbers

Use the following algorithm to write a program to find and print first n(10, 100, 1000 .. N) odd natural numbers; as follows:

  • Step 1: Start Program.
  • Step 2: Read the a number from user and store it in a variable.
  • Step 3: Find first n odd natural number using for loop or while loop or do while loop.
  • Step 4: Print first n odd natural number.
  • Step 5: Stop Program.

C Program to Print First N Odd Natural Numbers using For Loop

#include <stdio.h>

void main()
{
   int i,n;

   printf("Input number of terms : ");
   scanf("%d",&n);
   printf("\nThe Odd numbers are :");
   for(i=1;i<=n;i++)
   {
     printf("%d ",2*i - 1);
   }

} 

The output of the above c program; as follows:

Input number of terms : 5
The Odd numbers are :1 3 5 7 9 

C Program to Print First N Odd Natural Numbers using While Loop

#include <stdio.h>

void main()
{
   int i,n;

   printf("Input number of terms : ");
   scanf("%d",&n);
   printf("\nThe odd numbers are :");
   
   i = 1;

	while (i <= n)
	{
		printf("%d ", 2 * i - 1);
		i++;
	}

} 

The output of the above c program; as follows:

Input number of terms : 10
The odd numbers are :1 3 5 7 9 11 13 15 17 19 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.