Eof Controlled While Loop C++

  

Factorial Program in C++: Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example:

EofC++ while not eof

An EOF-controlled while loop is another name for a sentinel-controlled while loop. EOF stands for End of File. The function getc returns EOF, on success. Here is an example of EOF in C language, Let’s say we have “new.txt” file with the following content. The count-controlled while loop uses a loop control variable in the logical expression. The loop control variable should be initialized before entering the while loop, and a statement in the body of the while loop should increment/decrement the control variable. The following is a count-controlled while loop code segment.

Here, 4! is pronounced as '4 factorial', it is also called '4 bang' or '4 shriek'.

The factorial is normally used in Combinations and Permutations (mathematics).

C++ While Loop With Switch

There are many ways to write the factorial program in C++ language. Let's see the 2 ways to write the factorial program.

  • Factorial Program using loop
  • Factorial Program using recursion

Factorial Program using Loop

Let's see the factorial Program in C++ using loop.

Output:

Factorial Program using Recursion

Flag controlled while loop c++

Let's see the factorial program in C++ using recursion.

C++ Stream Eof

Output:

Eof Controlled While Loop C++ Loop

Next TopicArmstrong Number in C++
C++ while loop with switch