Lecture 20
Conditional Statements (Decision Making)
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int num1;
cout<<"Enter number : ";
cin>>num1;
if (num1%2 == 0) cout <<"Even number ";
if (num1%2 != 0) cout <<"Odd number ";
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int num1, num2;
cout<<"Enter first number : ";
cin>>num1;
cout<<"Enter second number : ";
cin>>num2;
if (num1*num1 == num2)
cout <<"Second number is square of first number ";
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10