kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Sunday, December 7, 2014

Đề bài:
Nhập m,n từ bàn phím.(m,n>2)
Tính tổng:
S = 1+ 2!/(m-2)! + ...+ n!/(m-n)! nếu m>n
S = 1+ 2!/(n-2)! + ...+ n!/(n-m)! nếu m<=n
Code:
#include<stdio.h>

int giaithua(int n)
{
int tich = 1;
for(int i=2;i<=n;i++) tich = tich*i;
//1*2*...*n
return tich;
}

float tinhS(int n,int m)
{
float S = 1;
for(int i=2;i<=m;i++)
{
S = S + (float)giaithua(i)/(float)giaithua((n-i));
}

return S;
}
int main()
{
int m,n;

do{
printf("Nhap m: "); scanf("%d",&m);
printf("Nhap n: "); scanf("%d",&n);
}while(m<=2||n<=2);
if(n>=m)
{
printf(" Tong S = %5.2f",tinhS(n,m));
}
else

printf(" Tong S = %5.2f",tinhS(m,n));

return 0;
}

0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts