N! (Hangdian 1042)

Source: Internet
Author: User
N! Time Limit: 10000/5000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 55971 accepted submission (s): 15886


Problem descriptiongiven an integer N (0 ≤ n ≤ 10000), your task is to calculate n!
 
Inputone N in one line, process to the end of file.
 
Outputfor each n, output n! In one line.
 
Sample Input
123
 
Sample output
126
# Include <stdio. h> int main () {int I, j, n, m; while (scanf ("% d", & N )! = EOF) {If (n <0) {continue;} int STR [10000] = {0}; STR [0] = 1; M = 0; for (I = 1; I <= N; I ++) // m is used to control carry. For (j = 0; j <= m; j ++) {STR [J] = STR [J] * I; if (j> 0 & STR [J-1]> = 10000) {STR [J] = STR [J] + STR [J-1]/10000; STR [J-1] = STR [J-1] % 10000;} If (STR [m]> = 10000) m ++;} printf ("% d ", STR [m]); for (I = m-1; I> = 0; I --) printf ("% 04d", STR [I]); printf ("\ n");} return 0 ;}


N! (Hangdian 1042)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.