C++ gurus and learners, we program ourselves :P all work is CC licensed

Wednesday, October 30

Fatorial using For loop

20:48 By

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
5! = 5  \times  4  \times  3  \times  2  \times  1 = 120.  \
The value of 0! is 1, according to the convention for an empty product
(for more info visit Factorial on Wiki )

Code:

#include
using namespace std;

int main()
{
 int factorial = 1, value = 1;
 cout << "Please enter value to find its factorial" << endl;
 cin >> value; int temporary = value;
 if (value < 0)
 {
  cout << "please enter a positive number ";
  main();
 }
 else if (value<2)
 {
  cout << "factorial of " << value << " is " << 1 << endl;
 }
 else
 {
  for (; temporary>1; factorial *= temporary--);
  cout << "factorial of " << value << " is " << factorial << endl;
  return 0;
 }
}


Tuesday, October 29

Fatorial using Do While loops

11:34 By

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
5! = 5  \times  4  \times  3  \times  2  \times  1 = 120.  \
The value of 0! is 1, according to the convention for an empty product
(for more info visit Factorial on Wiki )

Code:
you might write something in C#

#include
using namespace std;

int main()
{
 int factorial = 1, value = 1;
 cout << "Please enter value to find its factorial" << endl;
 cin >> value; int temporary = value;
 if (value < 0)
 {
  cout << "please enter a positive number ";
  main();
 }
 else if (value<2)
 {
  cout << "factorial of " << value << " is " << 1 << endl;
 }
 else
 {
  do
  {
   factorial *= temporary--;
  } while (temporary>1);
  cout << "factorial of " << value << " is " << factorial << endl;
  return 0;
 }
}

Programming Inventory

00:07 By


It is consisting of tools necessary for programming in any language.
(You can add your tools in comment section)

On top of the list is my favorite Codepad
 Microsoft Visual Studio C++ Express is freely available Here.