Learn C++ beginer programs

July 7, 2009

write a program to find greatest of two numbers

Filed under: cin,cout,else if,greatest,if,if else — snehilkhanor @ 3:19 pm
Two numbers are taken from user and greatest of two is determined.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b;
  7. cout<<”Please enter two nos. “;
  8. cin>>a>>b;
  9. if (a>b)
  10. cout<<”a is greatest”;
  11. else
  12. cout<<”b is greatest”;
  13. getch();
  14. }

July 5, 2009

Write a program to find greatest of three numbers

Filed under: cin,cout,else if,greatest,if,if else — snehilkhanor @ 6:27 pm
Three numbers are taken from user and greatest number is displayed.

Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c;
  7. cout<<”Please enter three nos. “;
  8. cin>>a>>b>>c;
  9. if (a>b)
  10. {
  11. if (a>c)
  12. cout<<”a is largest”;
  13. else
  14. cout<<”c is largest”;
  15. }
  16. else if (b>c)
  17. cout<<”b is largest”;
  18. else
  19. cout<<”c is largest”;
  20. getch();
  21. }

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.