Hello Everyone ! This time ,as i mentioned last time, we will discuss some examples related to what we have done. 1) W.A.P.(Write a Program) to enter 3 numbers and display the highest of them? Solution: #include<iostream> using namespace std; int main() { int a,b,c,max; cout <<"Enter 3 numbers:"; cin>>a>>b>>c; if(a>b && a>c) max=a; else { if(b>c) max=b; else max=c; } cout<<"\nMaximum = "<< max; return 0; } 2) W.A.P. to check whether a date entered in dd/mm/yy format is Valid or not? #include<iostream> using namespace std; int main() { int d,m,y,maxdays; char v='N'; cout<<"Enter a date as dd/mm/yy="; cin>>d>>m>>y; if(m>=1 && m<=12) { if (m==1 || m==3 || m==5 || m==7 || m==8|| m==10|| m==12) maxdays=31; else { if(m==2) { if((y%4...
Posts
Showing posts from June, 2017
- Get link
- X
- Other Apps
Hello Everyone. Now Lets Talk about the very useful if-else statements. It is a very simple type of Selective Statement but is of great Use. A If statement is Generally used to Compare Standard Data Types like integer,char ,double,etc. which is put inside parenthesis, whose result is given in either true or false,or 0 or 1, and is then checked by the compiler, if it is true ,the statements following this if statement will execute ,Otherwise it will not execute if statement block and execute the else block if present. An else block is a Block that executes in case if statement is not satisfied. Now Coming to the example.It will be more clear when you see the Example. int n=5; if(n>2) { n++; n = 2*n; } else{ n--; n=2*n; } Here, We have Declared a integer type variable n with value 5. Then there is an if statement with test expression = n>2 . Since, n=5 ,i.e., n>2 , Therefore, this condition is true and satisfied. Therefore , if statement block will execu...