C# Programming - Functions and Subroutines - Discussion

Discussion Forum : 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;
        } 
    } 
}
1
7
8
720
5040
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Rifathapps said:   9 years ago
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.

Nirmal said:   1 decade ago
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

Post your comments here:

Your comments will be displayed after verification.