Home > Backend Development > C++ > body text

C program to find the nth even number

WBOY
Release: 2023-09-07 19:05:02
forward
766 people have browsed it

C program to find the nth even number

Given a number N, we need to find the Nth even number.

An even number is a number that is divisible by 2 with a remainder of zero. For example, 2, 4, 6, 8, 10, etc.

If we look closely at lists of even numbers, we can also represent them as

2*1=2, 2*2=4, 2*3=6, 2*4=8,. ..2*N.

So, to solve this problem, we can simply multiply the number N by 2 so that the result is a number that is divisible by 2, i.e. an even number.

Example

Input: n = 4
Output: 8
The first 4 even numbers will be 2, 4, 6, 8, ..

Input: n = 10
Output: 20
Copy after login

Algorithm

START
   STEP 1-> DECLARE AND SET n AS 10
   STEP 2-> PRINT n*2 NUMBER
STOP
Copy after login

Example

#include <stdio.h>
int main(int argc, char const *argv[]){
   int n = 10;
   printf("Nth even will be:%d", n*2);
   return 0;
}
Copy after login

Output

Nth even will be:20
Copy after login

The above is the detailed content of C program to find the nth even number. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template