C++
#include<iostream>using namespace std
long long f(int n)
{
long long e=1
if(n>0)
e=n*f(n-1)
cout<<n<<"!="<<e<<endl
return e
}
int main()
{
int m=20
f(m)
return 0
}
C:
#include<stdio.h>int main()
{
int n, x
scanf("%d",&m)
for(n = x = 1 n <= m ++n) {
x *= n
printf("%d\t%d\n", n, x)
}
return 0
}
# includeint SumPrime(int n)
{
int i
int k
int sum=0
for(i=2i<=n++i )
{
for(k=2k<i++k)
{
if(i%k==0)
break
}
if(k == i) sum+= k
}
return sum
}
int main (void)
{
int n
int sum
printf("please enter a number:")
scanf("%d",&n)
sum=SumPrime(n)
printf("sum = %d\n",sum)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)