•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 427,788 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,738 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 2885 | Replies: 9
![]() |
youll need an outer loop which loops as high as the amount of factorials you want to compute, and an inner loop which will compute the factorial at the outer loops number.
pseudocode:
input n
set x = 1
loop n times
set num = 1
set y = 0
loop from x to 1
multiply num by y and re-store it into num
end loop
print num
end loop
that should do the job....unless i overlooked something
pseudocode:
input n
set x = 1
loop n times
set num = 1
set y = 0
loop from x to 1
multiply num by y and re-store it into num
end loop
print num
end loop
that should do the job....unless i overlooked something
Well, first of all you need to know what a factorial is. You haven't demonstrated that you know anything on how to solve this problem yet. If you need a description on what a factorial is here's a link.
http://mathworld.wolfram.com/Factorial.html
You would have to have a loop inside of a loop in order to make this work. Here's a little bit of code to get you started on your merry way:
the factorial is saved to the int result. If you want multiple answers just put the whole thing in a for loop incrementing factorial till you get to the desired value.
Hope this is helpful. I don't want to solve the whole thing for you though...
http://mathworld.wolfram.com/Factorial.html
You would have to have a loop inside of a loop in order to make this work. Here's a little bit of code to get you started on your merry way:
int factorial = 4;
int result = 1;
for (int i = 0; i < factorial; i++)
result *= i+1;
System.Console.WriteLine("result:" + result);the factorial is saved to the int result. If you want multiple answers just put the whole thing in a for loop incrementing factorial till you get to the desired value.
Hope this is helpful. I don't want to solve the whole thing for you though...
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
thanks a lot for the help both of ya guys..the way i did using the code above as following and worked perfectly fine for the results required...
static void Main(string[] args)
{
int num;
int j;
Console.WriteLine("Enter the number: ");
num = int.Parse(Console.ReadLine());
for (int i = 1; i <=num; i++)
{
Console.Write("1");
int total = 1;
for (j=1; j <= i; j++)
{
Console.Write("X" + j);
total = total*j;
}
Console.WriteLine(" = " + total);
}
}
static void Main(string[] args)
{
int num;
int j;
Console.WriteLine("Enter the number: ");
num = int.Parse(Console.ReadLine());
for (int i = 1; i <=num; i++)
{
Console.Write("1");
int total = 1;
for (j=1; j <= i; j++)
{
Console.Write("X" + j);
total = total*j;
}
Console.WriteLine(" = " + total);
}
}
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Nice program! I ran it and for factorial 13 I got 1932053504 when it should be 6227020800.
That because he used int type to total variable which can hold 2,147,483,647 as maximum positeve value.
You can change this line:
int total = 1;
to:
double total = 1;
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Problem opening / creating Dot net 2003 projects (Windows Servers and IIS)
- Error creating new ASP.Net project (ASP.NET)
- Creating and destroying objects (C++)
Other Threads in the C# Forum
- Previous Thread: HailStone
- Next Thread: Image in DataGridView



Linear Mode