[ create a new paste ] login | about

Link: http://codepad.org/zyJd3SnS    [ raw code | output | fork | 5 comments ]

C, pasted on Aug 17:
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	float x, S, T;
	long M;
	printf("\nNhap x: ");
	scanf("%f", &x);
	do
	{
	printf("\nNhap n: ");
	scanf("%d", &n);
	  if(n < 1)
	  {
		  printf("\n N phai >= 1. Xin nhap lai !");
	  }

	}while(n < 1);

	S = 0;
	T = 1;
	M = 1;
	i = 1;

	while(i <= n)
	{
		T = T * x;
		M = M * i;
		S = S + T/M;
		i++;
	}
	printf("\nTong la %f", S);
	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by caotuong226@gmail.com on Oct 23
ủa sao không đc bé hơn 1 ạ

reply
posted by banggiang2307 on Aug 13
vì n là interger, nếu n < 1 suy ra n = 0; mà n=0 thì ko thỏa mãn điều kiển toán học, phân số có mẫu phải khác 0
reply
posted by banggiang2307 on Aug 13
Bài 17: Tính S(n) = x + x^2/2! + x^3/3! + … + x^n/N!
reply
posted by banggiang2307 on Aug 13
// 17. S(n)=x+(x*x)/2!+...+(x^n)/(n!)
#include<stdio.h>

int main()

{
int i,n;
float T,M,S; //T= Tu_so; M=Mau_so; S=Tong;
S=0;
T=1;
M=1;
printf("\nMoi ban nhap gia tri cua n=");
scanf("%d",&n); //scanf_s("%d",&n);
printf("\nMoi ban nhap gia tri cua x=");
scanf("%f",&x); //scanf_s("%f",&x);
for(i=1;i<=n;i++)
{
T=T*x;
M=M*i;
S=S+(T/M);

}

printf("Tong S(n)=%f",S);
return 0;

}
/*Giai thich vong lap for theo toan hoc:
{
i=1--->T=T*x=x(vi T dc gan gia tri bang 1);
M=M*i=1(vi M dc gan gia tri bang 1 va i = 1);
==>S=S+T/M;
i=2-->T=T*x=x*x=x^2;
M=M*i=1*2=2!;
==>S= ;
i=3-->T=T*x=x^2*x=x^3;
M=M*i=2!*3=1*2*3=3!;
==>S= ;
...
...
...
...
Tong quat len:
i=n-->T=T*x=x^(n-1)*x=x^n;
M=M*i=(n-1)!*n=1*2*3*...*(n-1)*n=n!;
==>S= ;
}(Co the chung minh bang quy nap toan hoc)
reply
posted by banggiang2307 on Aug 13
// 17. S(n)=x+(x*x)/2!+...+(x^n)/(n!)
#include<stdio.h>

int main()

{
int i,n;
float T,M,S; //T= Tu_so; M=Mau_so; S=Tong;
S=0;
T=1;
M=1;
printf("\nMoi ban nhap gia tri cua n=");
scanf("%d",&n); //scanf_s("%d",&n);
printf("\nMoi ban nhap gia tri cua x=");
scanf("%f",&x); //scanf_s("%f",&x);
for(i=1;i<=n;i++)
{
T=T*x;
M=M*i;
S=S+(T/M);

}

printf("Tong S(n)=%f",S);
return 0;

}
/*Giai thich vong lap for theo toan hoc:
{
i=1--->T=T*x=x(vi T dc gan gia tri bang 1);
M=M*i=1(vi M dc gan gia tri bang 1 va i = 1);
==>S=S+T/M;
i=2-->T=T*x=x*x=x^2;
M=M*i=1*2=2!;
==>S= ;
i=3-->T=T*x=x^2*x=x^3;
M=M*i=2!*3=1*2*3=3!;
==>S= ;
...
...
...
...
Tong quat len:
i=n-->T=T*x=x^(n-1)*x=x^n;
M=M*i=(n-1)!*n=1*2*3*...*(n-1)*n=n!;
==>S= ;
}(Co the chung minh bang quy nap toan hoc)*/
reply