using System;
using System.Collections.Generic;
using System.Text;

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, n, fac = 1;
            string s;
            Console.Write("Please enter any number to find it's factorial(0 to 19):\n");
            s = Console.ReadLine();
            n = Int32.Parse(s); 
            for (i = 1; i <= n; i++)
            {
                fac = fac * i;
            }
            Console.WriteLine("\nThe factorial of '{0}' is {1}.",n,fac);
            Console.Read();
        }
    }
}

INPUT/OUTPUT: 5/120

<snipped>

Recommended Answers

All 5 Replies

Is this code supposed to mean something?

I think he is submitting this as a snippet...

c# syntax for factorial of the number
1.
using System;
2.
using System.Collections.Generic;
3.
using System.Text;
4.

5.
namespace Factorial
6.
{
7.
class Program
8.
{
9.
static void Main(string[] args)
10.
{
11.
double i, n ;
int fac = 1;
12.
string s;
13. Console.Write("Please enter any number to find it's factorial:\n");
14. s = Console.ReadLine();
15. n = Int32.Parse(s);
16. for (i = 1; i <= n; i++)
17. {
18. fac = fac * i;
19. }
20. Console.WriteLine("\nThe factorial of '{0}' is {1}.",n,fac);
21. Console.Read();
22. }
23. }
24. }

Allright... but this is horribly obvious code.

:ooh: Yeah, every morning the sun comes up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.