Tuesday, September 9, 2014

More Example Programs


IF ELSE STATEMENT
1.)
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
   int a;
   cout<<"Enter the Number :";
   cin>>a;
   if(a > 10)
   cout<<a<<" Is Greater than 10";
   else
   cout<<a<<" Is Less than/Equal 10";

    _getch();
    return 0;
 }

2.)













IF ELSE IF STATEMENT

1.)

#include <iostream.h>
#include<conio.h>

using namespace std;
 
int main(void)
{

int per;
 
cout << "Enter your Percentage::";
 
cin >> per;
 
if (per >=80 )
 
{ cout << "Passed with Distinction" << endl;}
 
else if (per >=70 )
 
{ cout << "Passed with High Firstclass" << endl;}
 
else if (per >=60 )
 
{ cout << "First Class" << endl; }
else if (per >=50)
 
{ cout << "Second Class" << endl; }
else
{ cout << "Third Class" << endl; }


_getch();
return 0;
 
}

2.)

#include <iostream.h> #include<conio.h> using namespace std; int main(void) { int age, height; cin >> age; cin >> height; if(height == age) cout << "Your height is equal to your age!"; else if(height < age)
cout << "Your height is less than your age!"; else if(height > age) cout << "Your height is greater than your age!"; _getch(); }

NESTED IF ELSE STATEMENT

1.)

#include <iostream.h>
 

#include<conio.h>
using namespace std;
 

int main(void)
 
{

int age;
 
cout << "Enter your Age::";

cin >> age;
 
if (age >=10 && age<=50)
 
   {
   if (age >=10 && age <= 18)
 
   {cout << "You are a Teenage" << endl;}
 
   else
 
   { cout << "You not a Teenager" << endl;}

   }

else
 
{ cout << "You are more than 50 years" << endl;}

_getch();

return 0;
 
}

2.)


#include <iostream> 
#include <cstdlib> 

#include<conio.h>
 
using namespace std; 
 
int main() 

  int magic;   
  int guess;    
 
  magic = rand();              // get a random number 
   
  cout << "Enter your guess: "; 
  cin >> guess; 
 
  if (guess == magic) { 
    cout << "** Right **\n"; 
    cout << magic << " is the magic number.\n"; 
  } 
  else 
    cout << "...Sorry, you're wrong."; 
    if(guess > magic) 
       cout <<" Your guess is too high.\n"; 
    else 
       cout << " Your guess is too low.\n"; 
  } 
 

  _getch();
  return 0; 
}

23 comments:

  1. Thanks for this blog. this helps me a lot.

    ReplyDelete
  2. A great help, indeed.

    ReplyDelete
  3. Thanks for the samples. :)

    ReplyDelete
  4. Very meaningful and helpful blog. :)

    ReplyDelete
  5. Thanks For this informative blog :)

    ReplyDelete
  6. magagamit to sa mga assignment :)

    ReplyDelete
  7. programming is real hard but with the help of this blog i will be guided

    ReplyDelete
  8. malaking tulong to sa mga students :D

    ReplyDelete
  9. malaking tulong to sa mga students :D

    ReplyDelete
  10. Thanks for the info :))) Mam Memeh.

    ReplyDelete
  11. Thanks for the info :))) Mam Memeh.

    ReplyDelete
  12. anhirap ng programming .. thanks for this one.. keep it up girl!

    ReplyDelete
  13. Mooore! hahahah.thnks for this blog!

    ReplyDelete
  14. Very helpful... thanks for the blog..

    ReplyDelete
  15. it really helps!! thank you...

    ReplyDelete
  16. thank you for the examples!!

    ReplyDelete
  17. one of you examples is related to the program that i am doing..
    this serves as my guide.. thanks!

    ReplyDelete
  18. Thanks for the samples ^^ this is a very helpful blog for us students

    ReplyDelete
  19. such a good aid for my assignments.. thanks

    ReplyDelete
  20. i now understand it because of this samples.. thanks!

    ReplyDelete