A Simple C++ Example

// This is a simple program that sets
// a variable to 3, then calculates
// it's square and prints the result
// on the screen

#include <iostream.h>

int square(int value);

int Number;

void main(void)
{
   int result;

   Number = 3;
   result = square(Number);
   cout << "The result is " << result;
}

int square(int value)
{
   return value * value;
}
Previous page
Next page

Back to Lesson 2 Index
Back to Outline