
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program for n-th odd number
Given a number N we have to find the N-th odd number.
Odd numbers are the numbers which are not completely divided by 2 and their remainder is not zero. Like 1, 3, 5, 7, 9,….
If we closely observe the list of even numbers we can also represent them as
(2*1)-1=1, (2*2)-1=3,( 2*3)-1=5, (2*4)-1=7,….(2*N)-1.
So, to solve the problem we can simply multiply the number N with 2 and subtract 1 from the result, that makes up an odd number.
Examples
Input: 4 Output: 7 The 4th odd number is 1, 3, 5, 7.. Input: 10 Output: 19
Algorithm
START STEP 1 -> Declare and assign an integer ‘n’. STEP 2 -> Print n*2-1(odd number). STOP
Example
#include <stdio.h> int main(int argc, char const *argv[]){ int n = 10; //for odd numbers we can simply subtract 1 to the even numbers printf("Nth odd number = %d", n*2-1); return 0; }
Output
Nth odd number = 19
- Related Articles
- C Program for n-th even number
- C/C++ Program for the n-th Fibonacci number?
- Python Program for n-th Fibonacci number
- Java Program for n-th Fibonacci number
- N-th Fibonacci number in Python Program
- N-th Tribonacci Number in C++
- N-th polite number in C++
- C++ Program for Area Of Square after N-th fold
- C Program for N-th term of Geometric Progression series
- C Program for N-th term of Arithmetic Progression series
- C/C++ Program for Finding the Number Occurring Odd Number of Times?
- N-th root of a number in C++
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- Java program for removing n-th character from a string

Advertisements