zoukankan      html  css  js  c++  java
  • 题目1067:n的阶乘--------long long int

    此题不难,关键是20的阶乘是long long int 型的,这点需要注意!

    AC不用递归的代码:

     #include<iostream>
    using namespace std;
    
    int main()
    {
    	int n;
    	long long int res=1;
    	
    	while(cin>>n)
    	{
    	   int i=1;
    	    res=1;;
    		for (i=1;i<n+1;i++)
    		  res=res*i;
    	  cout<<res<<endl;
    	}
    	return 0;
    } 
    

    AC用递归的代码:

    #include<iostream>
    using namespace std;
    
    long long int fact(int n);
    int main()
    {
    	int n; 
    	while(cin>>n)
    	{
    	  cout<<fact(n)<<endl;
    	}
    	return 0;
    } 
    long long int fact(int n)
    {
    	if (n==1)return 1;
    	else return n*fact(n-1); 
    }
    

      

     

  • 相关阅读:
    Docker
    Alfred Workflow
    AWS Lambda
    XPath
    WebMagic
    Splash
    Selenium
    代理服务器
    JSONPath
    Sqlserver 查询分组 记录
  • 原文地址:https://www.cnblogs.com/jianrenguo/p/6481082.html
Copyright © 2011-2022 走看看