السلام عليكــم ورحمـة الله وبركاتــه
اتمنى تردون علي بسرعه
سؤال يحسب
Write a program that computes and print the value of ex by using the formula:
ex = 1 + x/1! + x2/2! + x3/3! +….....+ xn/n! [Hint: use nested For loop
وهذا الكود
اريد انا اعرف ايش المشكله
اذا دخلت x=2 ,n=2
يطلعلي 5وهذا صح بس باقي الارقام يكون الناتج خطأ
اريد تصحيح الكود فقط
لا تحطون كود ثاني
معليش اتشرط
وجزاكم الله الف خير
#include<iostream>
using namespace std;
int main()
{
float fac=1,sum=1,pow=1;
int x,n;
cout<<"x";
cin>>x;
cout<<"n";
cin>>n;
for(int i=1;i<=n ;i++)
{
for(int j=n;j>=1;j--)
{
fac=fac*j;
}
for(int y=1;y<=x;y++)
{
pow=pow*x;
}
}
sum=sum+float(pow/fac);
cout<<"sum "<<sum<<endl;
system("pause");
return 0;
}
