Basic Programming Elements

In this tutorial we overview the basic elements of a programming language such as decisions, loops, and functions.

 

Tasks

Write a single program for each of the following:

Issues

Write mechanisms for each program to verify the input and output.

C++ Reference Implementation

#include<iostream>
#include<cmath>
long factorial(long number)
{
  long result = 1;
  for (long i =1 ; i <= number; ++i)
    {
      result *= i;
    }
  return result;
}
int main()
{
  long a;
  std::cout << "Please enter a: " ;
  std::cin >> a;
  std::cout << "the factorial of " << a << " is: " << factorial(a) << std::endl;
  return 0;
}