closed How to make a program to find out odd or even numbers?

+4 votes
asked Jun 19, 2018 by Ashraful Islam Tanzil 2 flags
closed Jun 11 by Admin
Please give me a easy learning script as a example.
closed with the note: Closing question, since it has been answered

36 Answers

+1 vote
answered Jun 20, 2018 by Asdrubal Lopez Chau (200 points)

#include <iostream>

using namespace std;

int main()
{
    int number;
    
    cout<<"Introduce a number:";
    cin>>number;
    if (number %2 == 0) { //Residue cero, then even
        cout<<"Even number"<<endl;
    } else {
        cout<<"Odd  number"<<endl;
    }
    return 0;
}

commented Feb 26, 2019 by khalidDaghameen (100 points) 1 flag
you don't need equality operator
commented Mar 3 by anonymous
you don't but it is good programming to write it explicitly
commented May 3 by Aneesha Merlin (100 points)
is the above program is a c prgm???
the header file used is iostream which is  used for the C programming
commented Jun 11 by Peter Minarik (7,040 points)
The above is not C, but C++.
"iostream" is a C++ library. In C you should use "stdio.h".
+1 vote
answered Jun 21, 2018 by KaarthikAravinth (160 points)
#include<stdio.h>

int main()

{

int a;

printf("enter the no's to check odd or even");

scanf("%d",&a);

if(a%2==0)

{

printf("the no is even");

}

else

{

printf("the no is odd");

}

return 0;

}
+1 vote
answered Jun 21, 2018 by ANANTH BALAJI P (160 points)
#include<stdio.h>

void main()

{

int a;

printf("enter a number");

scanf("%d",&a);

a%2==0?even:odd;

}
commented Feb 26, 2019 by khalidDaghameen (100 points)
it does give an error , doesn't it?
0 votes
answered Jun 21, 2018 by prem bhai (140 points)
#include<iostream>
using namespace std;
int
main ()
{
  int x;
  cout << "enter the number.." << endl;
  cin >>x;
 if(x%2==0)
 {
     cout << "the number is even number... "<<endl;
 }
 else
  {
      cout << "the number is odd number..." <<endl;

  }
  }
0 votes
answered Jun 21, 2018 by anonymous
# include<iostream>

using namespace std;

int main()

{

int  num;

cout<<"Enter Number "<<endl;

cin>>num;

if(num %2==0)

cout<<"even Number "<<endl;

else

cout<<"odd Number"<<endl;

}
0 votes
answered Jun 21, 2018 by ayush khurana (140 points)
include<stdio.h>

int main()

{

int n;

printf("Enter the number:");

scanf("%d",&n);

if(n%2=0)

{
printf("the number is even: %d",n);

}

else

{

printf("The number is odd:");

}

}
0 votes
answered Jun 22, 2018 by 17H51A0473 (140 points)
#include<stdio.h>

void main()

{

int n;

scanf("%d",&n);

if(n%2==0)

printf("The given number is an Even Number");

else

printf("The given number is an Odd Number");
0 votes
answered Jun 24, 2018 by SRM 2000 (210 points)
#include<stdio.h>

int main()

{

int a=0;

printf("Enter the value of a :\n");

scanf("%d",&a);

if(a%2==0)

printf("The number is even.\n");

else

printf("The number is odd\n");

return 0;
commented Feb 25 by jestadi vickyath (140 points)
dont forget the brackets.... pls add it
0 votes
answered Jun 25, 2018 by mrinalchandra (140 points) 1 flag

#include<stdio.h>

int main()

{

   int a;

printf( "enter the number to be check:");

scanf("%d",&a);

if(a%==0)

{

printf("the entered number is even");

}

else

{

printf("the entered number is odd");

}

return 0;

}

+1 vote
answered Jun 25, 2018 by vaishnavi
#include<stdio.h>

void main()

{

int i;

for(i=1;i<=10;i++)

if(i%2==0)

{

printf("even numbers");

printf("%d",i);

}

else

{

printf("odd numbers");

}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...