+ 4

How can i show multiplication of numbers from n to 1? For example :-in a factorial if i want to show the multiple then how ?

24th Dec 2018, 6:58 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
10 Answers
+ 6
You already made a code that works and does exactly what you're asking for: https://code.sololearn.com/cI44dM80i54q/?ref=app The problem is that it'll only work for relatively small numbers because integers are quite limited and factorials tend to be huge numbers. To make it work with a larger range of numbers, you can change the data type of f from int to something like unsigned long.
24th Dec 2018, 7:07 AM
Anna
Anna - avatar
+ 4
Oh, so you want to display the numbers that are multiplied? You're already using a for loop to multiply the numbers. You can use the same loop to print the numbers, followed by a '*' if n is > 1, so you'll get 5*4*3*2*1. Try to do it, it's not that hard.
24th Dec 2018, 7:19 AM
Anna
Anna - avatar
+ 2
Don't panic, Titiksha, just as Anna has said, it's not that hard, you can do this 😉 Some hints for you Titiksha. 1. You need to use brackets {} in the for loop because the command will be more than one line. 2. Currently the line break is \n You don't want to print line break if you want to print 5*4*3*2*1 3. You need to print an equal sign = without line break before the for loop
24th Dec 2018, 7:32 AM
Gordon
Gordon - avatar
+ 1
Can you specific the language and give an example of output?
24th Dec 2018, 7:08 AM
Gordon
Gordon - avatar
0
language is C Output that i want: factorial of a number, (say 5) = 5! = 5*4*3*2*1 =120
24th Dec 2018, 7:13 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
0
pls tell me the code for achieving this for any number n
24th Dec 2018, 7:30 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
0
I was typing, lol.
24th Dec 2018, 7:34 AM
Gordon
Gordon - avatar
0
Titiksha Tyagi, 100% of what you need to finish the code is already used in your code. Your idea to use a for loop to multiply the numbers is much more clever than what it takes to take the last step and print the numbers. You have a for loop that goes from n to 1. Print each number, you know how to do that. If n is greater than 1, also print an asterisk (*). That's all you need to do to get the result 5*4*3*2*1.
24th Dec 2018, 7:54 AM
Anna
Anna - avatar
0
I tried a lot but i can't able to do it so pls give me the code and not only the hint
25th Dec 2018, 3:32 PM
Titiksha Tyagi
Titiksha Tyagi - avatar
- 1
EVCPlus
24th Dec 2018, 9:40 AM
wadani