Wednesday, 9 September 2015

C++ Program to print greatest of two numbers

This program asks the user to input two numbers and outputs the greatest of the two numbers.

#include <iostream.h>

void main()
{
int a,b;
cout << "Enter a number : ";
cin >>  a;
cout << "\nEnter another number : ";
cin >> b;
cout << "The largest number is : " << a>b:a?b;
}

If you need explanations, just comment. :D

Hello World C++ Program

Programming begins from an Hello World. This post will show you how to write a C++ program to print the text "Hello World!" on the screen.

#include <iostream.h>
#include <conio.h>
void main()
{
cout << "Hello World!";
getch();
}

The above program works on compilers which use the original C++ standard such as Turbo C++. For those who follow the latest C++ 11 standards, the code is as follows :

#include <iostream>
void main()
using namespace std;
{
cout << "Hello World!";
}