C/C++ Program to determine whether a given number is odd or even & print the message the number is odd or even without using else option
Program
# include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the number: ");
scanf ("%d", &a);
if(a%2==0)
{
printf("\n Number is Even");
}
if(a%2!=0)
printf("\n Number is Odd");
getch()
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
Program
# include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the number: ");
scanf ("%d", &a);
if(a%2==0)
{
printf("\n Number is Even");
}
if(a%2!=0)
printf("\n Number is Odd");
getch()
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
No comments:
Post a Comment