Program to illustrate nested If statement

/* Program : The nested If statement */

#include <iostream.h>
main()
{
    int a ;
    cout<<"Enter a number : " ;
    cin>>a ;
    if (a%3 == 0)
              if (a%5 == 0)
            cout<<"The number is divisible by 3 and 5" ;
}
--------------------------------------------

/* Program:   Minimum of three numbers-Using nested if else statements*/
#include <iostream.h>
void main()
{
    int n1, n2, n3;
    cout << "Enter three integers: ";
    cin >> n1 >> n2 >> n3;
    if (n1 < n2)
        if (n1 < n3)
    cout << "Smallest number is : " << n1 << endl;
        else    
            cout << "Smallest number is : " << n3 << endl;

    else  // n1 >= n2

    if (n2 < n3)
    cout << "Smallest number is " << n2 << endl;
    else
    cout << "Smallest number is " << n3 << endl;
}


0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|