下面的代码用于查找给定数字的阶乘,但是不能找到100的阶乘,但是对于像5这样小的数字可以正常工作! [英] The following code used for finding the factorial of a given number but is not able to find a factorial of 100 but works fine with numbers smaller like 5!

查看:56
本文介绍了下面的代码用于查找给定数字的阶乘,但是不能找到100的阶乘,但是对于像5这样小的数字可以正常工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码查找给定数字的阶乘,但此代码只能找到较小数字的阶乘,当较大数字(如100或更多)显示为零且输出类似于因子100为0时你能帮我解决一下这段代码吗。



我尝试了什么:



This code finds the factorial for a given number but this code is only able to find the factorial for only smaller numbers, when larger numbers like 100 or more it shows zero and the output is like "The factorial of 100 is 0", could you please fix this code for me.

What I have tried:

#include<stdio.h>
unsigned long long factorial(unsigned long long x);
int main(void)
{
     unsigned long long a=100, fact;
     
     fact= factorial(a);
     
     printf("the factorial of %llu is %llu",a,fact);
}

unsigned long long factorial(unsigned long long x)
{
            unsigned long long f;
	if(x==1)
	return (1);
	
	else
	
	f= x*factorial(x-1);
	return (f);
}

推荐答案

无符号长整数的最大值 [ ^ ]是2 64 -1。 100! factorial比那个大。
The max value of an unsigned long long[^] is 264-1. 100! factorial is way bigger than that.


这篇关于下面的代码用于查找给定数字的阶乘,但是不能找到100的阶乘,但是对于像5这样小的数字可以正常工作!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆