Odd and even number between a range program

Odd and even number range in c

#include<stdio.h>
#include<conio.h>
void Show(int start,int end);
void main()
{
int start,end;
printf("Enter your starting index \n");
scanf("%d",&start);
printf("Enter your ending index \n");
scanf("%d",&end);
Show(start,end);
getch();
}
void Show(int start,int end)
{
printf("Your even numbers are \n");
for (int i = start; i <= end; i++)
{
if (i % 2 == 0)
{
printf("%d \n",i);
}
}
printf("Your odd numbers are \n");
for (int i = start; i <= end; i++)
{
if (i % 2 != 0)
{
printf("%d \n",i);
}
}
}

Output

Enter your starting index
20
Enter your ending index
30
Your even numbers are
20
22
24
26
28
30
Your odd numbers are
21
23
25
27
29

Odd and even number range in c++

#include<iostream>
#include<conio.h>
using namespace std;
class EvenOddSeries
{
public:
void Show(int start,int end)
{
cout<<"Your even numbers are \n";
for (int i = start; i <= end; i++)
{
if (i % 2 == 0)
{
cout<<i<<"\n";
}
}
cout<<"Your odd numbers are \n";
for (int i = start; i <= end; i++)
{
if (i % 2 != 0)
{
cout<<i<<"\n";
}
}
 
}
 
};
void main(){
int start,end;
cout<<"Enter your starting index \n";
cin>>start;
cout<<"Enter your ending index \n";
cin>>end;
EvenOddSeries ev;
ev.Show(start,end);
getch();
}

Output

Enter your starting index
10
Enter your ending index
20
Your even numbers are
10
12
14
16
18
20
Your odd numbers are
11
13
15
17
19

Odd and even number range in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace EvenOddSeries
{
class Program
{
public void Show(int start,int end)
{
Console.WriteLine("Your even numbers are");
for (int i = start; i <= end; i++)
{
if (i % 2 == 0)
{
Console.WriteLine(i);
}
}
Console.WriteLine("Your odd numbers are");
for (int i = start; i <= end; i++)
{
if (i % 2 != 0)
{
Console.WriteLine(i);
}
}
 
}
static void Main(string[] args)
{
Console.WriteLine("Enter your starting index");
int start = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter your ending index");
int end = Convert.ToInt32(Console.ReadLine());
Program p1 = new Program();
p1.Show(start, end);
Console.ReadLine();
}
}
}

Output

Enter your starting index
1
Enter your ending index
10
Your even numbers are
2
4
6
8
10
Your odd numbers are
1
3
5
7
9

Odd and even number range in java

import java.util.*;
class AB
{
	public void Show(int start,int end)
	{
		System.out.println("Your even numbers are \n");
		for(int i=start;i<=end;i++)
		{
			if(i%2==0)
			{
				System.out.println(i);
			}
		}
		System.out.println("Your odd numbers are \n");
		for(int i=start;i<=end;i++)
		{
			if(i%2!=0)
			{
				System.out.println(i);
			}
		}
	}
	
}
class examples
{
public static void main(String[] args)
	{
     int a,b;
     Scanner obj= new Scanner(System.in);
     System.out.println("Enter your starting index \n");
     a=obj.nextInt();
     System.out.println("Enter your ending index \n");
     b=obj.nextInt();
     AB ab=new AB();
     ab.Show(a, b);
	}

}

Output

Enter your starting index 

10
Enter your ending index 

20
Your even numbers are 

10
12
14
16
18
20
Your odd numbers are 

11
13
15
17
19

Write a comment


Name Email Message