السلام عليكــم ورحمـة الله وبركاتــه ،،كيف حالك إن شاء الله دائمــاً بخير ؟ بين يدي سؤال بسيط وقمت بحله لكن اريد التأكد من حله هل هو صحيح اما خاطئ ؟؟
Write a C++ program that will compute the factorial of all numbers between 2 given numbers. The 2 numbers are entered by the user where the second number must be greater than the first (both numbers must be positive).
االحل :
using namespace std;
int main()
{
int fact,num1,num2;
cout<<"Please Enter 2 numbers :: ";
cin>>num1>>num2;
cout<<"\n";
if ((num1>0)&&(num2>0))
{
if (num2>num1)
{
for(num1;num1<=num2;num1++)
{
fact=1;
for(int i=1;i<=num1;i++)
fact*=i;
cout<<"number :"<<num1<<"\t"<<"factorial :"<<fact;
cout<<endl;
}
}
else
cout<<" The num1 greater than num2 :: error ";
}
else
cout<<" The num1 and num2 must be are positive ";
return 0;
}
#include <iostream>
