C Program to Generate Even Numbers Between Two Integers

C program to generate even numbers between 2 integer values input by the user.

Related Read:
Even or Odd Number: C Program
Even or Odd Number without using Modular Division: C Program

Note 1: An even number is an integer that is exactly divisible by 2.

Note 2: Even numbers are of the form 2 * n;

Note 3: Modular division( % ) returns remainder of division. For example, 10 / 2 = 5. But 10 % 2 = 0.

C Program to Generate Even Numbers Between Two Integers

 
#include<stdio.h>

int main()
{
    int count, limit;

    printf("Enter start value and end value to generate Even no's\n");
    scanf("%d%d", &count, &limit);

    printf("\nEven numbers between %d and %d are:\n", count, limit);

    while(count <= limit)
    {
        if(count % 2 == 0)
        {
            printf("%d\n", count);
        }
        count++;
    }

    return 0;
}

Output 1
Enter start value and end value to generate Even no’s
10
30

Even numbers between 10 and 30 are:
10
12
14
16
18
20
22
24
26
28
30

Output 2
Enter start value and end value to generate Even no’s
1
10

Even numbers between 1 and 10 are:
2
4
6
8
10

C Program to Generate Even Numbers Between Two Integers


[youtube https://www.youtube.com/watch?v=cE25_Fm7eMU]

YouTube Link: https://www.youtube.com/watch?v=cE25_Fm7eMU [Watch the Video In Full Screen.]


In above c program, we ask the user to input 2 integer value and store it in variables count and limit. While loop keeps executing until the start value i.e., count is less than or equal to the end value i.e., limit.

Inside while loop, for every value of count, we check if its perfectly divisible by 2. If true, it’s a Even number and we output that number to the console window. On every iteration of the loop we increment the value of count by 1.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Update:
In the above video I’ve said: “count should be exactly divisible by 0”.

I’m sorry about that. It should be – “Value inside variable count should be exactly divisible by 2.”

Count Method: MongoDB

Let’s learn to use count() method in MongoDB.

Count method outputs numeric value of the number of documents retrieved.

count-method-mongodb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
> use test
switched to db test
> db.names.find().pretty()
{ "_id" : ObjectId("53be5d4604cc1cb0a7bfc3c0"), "name" : "Alia" }
{ "_id" : ObjectId("53be5d5204cc1cb0a7bfc3c1"), "name" : "Bebo" }
{ "_id" : ObjectId("53be5d5904cc1cb0a7bfc3c2"), "name" : "Chameli" }
{ "_id" : ObjectId("53be5d6104cc1cb0a7bfc3c3"), "name" : "Dev D" }
{ "_id" : ObjectId("53be5d6804cc1cb0a7bfc3c4"), "name" : "Emli" }
{ "_id" : ObjectId("53be5d8604cc1cb0a7bfc3c5"), "name" : "Farhan" }
{ "_id" : ObjectId("53be5d9204cc1cb0a7bfc3c6"), "name" : "Gangs" }
{ "_id" : ObjectId("53be5d9904cc1cb0a7bfc3c7"), "name" : "Hum" }
{ "_id" : ObjectId("53be5e3704cc1cb0a7bfc3c8"), "name" : 25 }
> db.names.count();
9
> db.names.count({"name": {$type: 2}});
8
> db.names.count({"name": {$type: 1}});
1
> db.names.count({"name": {$regex: "e"}});
3

We have 9 documents, out of which 8 documents have string values as name and 1 document has numeric value as it’s name.

Count Method: MongoDB


[youtube https://www.youtube.com/watch?v=1Cx0KT43xlw]

YouTube Link: https://www.youtube.com/watch?v=1Cx0KT43xlw [Watch the Video In Full Screen.]



Related Read: $exists, $type, $regex operators: MongoDB

$type: 2, represents string value in BSON specification. And we have 8 documents with string value for the name field.

$type: 1, represents double value in BSON specification. And we have 1 document with numeric value for the name field.

$regex: “e”, we have 3 documents which has small letter e in the string value for name field.

Note: We can make use of count() method, when we want to show the number of friends or followers each member has. So MongoDB makes it easy by facilitating developers with count() method.

SELECT / LIST Records From Database Table: PHP & MySQL
In sql, we have SELECT count(*) FROM table_name;