Вы находитесь на странице: 1из 1

Passing the 1st exit test at CTS:

Sample Ques.:
Q) Create a function which has got one input parameter named input1. Find the
factorial of this number and store it in output1 variable which is a global variable.
Business rules:
1) If input1 is a -ve number store -1 to output1 variable.
2) If input1 is greater than 10 store -2 to output1 variable.
How to solve: The best approach to getting full marks
Solution:int output1;
void calculateFact(int input1)
{
if(input1<0)
{
output1=-1;
}
if(output1!=-1 && input1>10)
{
output1=-2;
}
if(output1!=-1 && output1!=-2)
{
int fact=1,i=1;
for(i=1;i<=input1;i++)
{
fact=fact*i;
}
output1=fact;
}
}

That's it

Вам также может понравиться