Example if else statement:
Logic:
If we
divide a number with 2 if the reminder is zero then the number is even
otherwise the number will be odd. In c++ for find the reminder we use
arithmetic operator “%” . so this is
the logic of our program that we use in our program.
program:
#include "stdafx.h"
#include "iostream"
#include"conio.h"
using namespace std;
void main()
{
int num;
cout<<"enter
the number==";
cin>>num;
//input the number
if(num%2==0)
cout<<”number”<<num<<” is
even”; //display output is
condition is true
else
cout<<”number”<<num<<” is odd”; //display output is condition is
false
_getch(); //function use for display the all
output until we press a char
}
0 comments:
Post a Comment