1. 程式人生 > >C語言求1!+2!+3!........10!

C語言求1!+2!+3!........10!

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int i = 0;
	
	int sum = 0;
	int res = 1;
	for (i = 1; i <= 10; i++)
	{
		res = res*i;
		sum = sum + res;
	}
	printf("sum = %d\n", sum);
	system("pause");
	return 0;
}
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int i = 0;
	int j = 0;
	int sum = 0;
	
	for (i = 1; i <= 3; i++)
	{
		int res = 1;
		for (j = 1; j <= i; j++)
		{
			res = res*j;
		}
		sum = sum + res;
	}
	printf("sum = %d\n", sum);
	system("pause");
	return 0;
}