/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: compile a console application. Use the for, while, and do-while statements to calculate n!
* Author: Lei hengxin
* Completion date: January 1, September 08, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
[Csharp]
<Span style = "font-size: 24px;"> using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("this is a loop control statement that uses for while do-while to calculate n! ");
Console. Write ("Enter the number :");
String n = Console. ReadLine ();
Int I, m = 1;
Int x = int. Parse (n); // type conversion
For (I = 1; I <x; ++ I)
{
M = m * (I + 1 );
}
Console. WriteLine ("Use the for loop control statement to calculate {0 }! Value: {1} ", x, m );
I = 1;
M = 1;
While (I <x)
{
M = m * (I + 1 );
++ I;
}
Console. WriteLine ("Use the while loop control statement to calculate {0 }! Value: {1} ", x, m );
I = 1;
M = 1;
-- X;
Do
{
M = m * (I + 1 );
++ I;
} While (I <= x );
Console. WriteLine ("Use the do-while loop control statement to calculate {0 }! Value: {1} ", (x + 1), m );
Console. ReadKey ();
}
}
}
</Span>
Running result:
Experience Accumulation:
1. The for while do-while statements in C # And C ++ are identical.