C# Programming - Functions and Subroutines - Discussion

Discussion :: Functions and Subroutines - General Questions (Q.No.16)

16. 

What will be the output of the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{
    class SampleProgram
    {
        static void Main(string[ ] args)
        {
            int i;
            int res = fun(out i);
            Console.WriteLine(res);
        }
        static int fun (out int i)
        {
            int s = 1;
            i = 7;
            for(int j = 1; j <= i; j++)
            {
                s = s * j;
            }
            return s;
        } 
    } 
}

[A]. 1
[B]. 7
[C]. 8
[D]. 720
[E]. 5040

Answer: Option E

Explanation:

No answer description available for this question.

Nirmal said: (Jun 21, 2012)  
Initial s=1, i=7;
In loop j initialized to 1 loops upto <=7
s=1*1;
s=1*2;
.
.
.
s=720*7;
return (5040);

In fun call it prints value 5040

Rifathapps said: (May 4, 2016)  
s = 1 * 1 = 1.
s = 1 * 2 = 2.
s = 2 * 3 = 6.
s = 6 * 4 = 24.
s = 24 * 5 = 120.
s = 120 * 6 = 720.
s = 720 * 7 = 5040 --> Answer.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.