Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Given a simple program designed to take inputs of integers
from 1-1000 and to output the factorial value of that
number, how would you test this program? You do not have
access to the code. Please be as specific as possible.

Answers were Sorted based on User's Feedback



Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial..

Answer / min soo kim

If the function that takes integers from 1 to 1000 can be
considered function f(n), then we could write the following
line of code

int i = 0;
int is_incorrect = 0;
for(i = 2; i <= 1000; i++)
{
// This is a simple for loop to divide a f(n) factorial
with f(n-1) factorial, which would give the result of n.
if(f(i) / f(i-1)) !- i)
{
is_incorrect = 1; // Mark the flag as incorrect, since
we did not get the value that we want.
break;
}
}

Is This Answer Correct ?    17 Yes 4 No

Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial..

Answer / tudor

write some programs to take a string input assumed to be
1000! 999! 500! or 1!, test the asspumption. and ouput the
result "OK" or "NOT OK"
Pass the output of program to be tested to your programs
using some scripting
e.g:
echo "testig 1!"
echo `echo "1" > targetprogram | test1fact`
echo "testig 500!"
echo `echo "500" > targetprogram | test500fact`
...

Also should test the output for 1001, 0, xyz, -1

Is This Answer Correct ?    0 Yes 0 No

Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial..

Answer / vaibhav nigam

@ Min Soo Kim

i will use your concept but in a better way like:
there is no need to make any f() function to calculate
factorial.

some lines of code:

main()
{
int a,b;
cin >> a;
bool check=1; //'1' for correct and '0' for wrong answer
if(a!=1)
check=0;
else {
for(int i=2; i<=1000; i++) {
cin >> b;
if(a*i!=b) {
check=0;
break;
}
a=b;
}
}
if(check)
printf("correct");
else
printf("wrong");
}


// since factorial(1000) is a very large value, so another
container can be used but logic remains same

Is This Answer Correct ?    0 Yes 0 No

Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial..

Answer / arati pradhan

Input 1 --> Check the result
Input 500 --> Check the result
Input 999--> Check the result
Input 1000-->Check the result

Is This Answer Correct ?    7 Yes 9 No

Post New Answer

More C++ General Interview Questions

Explain linked list using c++ with an example?

0 Answers  


What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

0 Answers  


What do you understand by zombie objects in c++?

0 Answers  


Is string data type in c++?

0 Answers  


What is optimization in c++? when using volatile.optimization is not possible..what does this mean?

1 Answers  


Can we use resume in error handling i.e. in the catch block

5 Answers   Infosys,


Write a Program for read a line from file from location N1 to N2 using command line arguments. Eg:exe 10 20 a.c

0 Answers  


program explaining feautures of c++

0 Answers   Satyam,


What are advantages of using friend classes?

0 Answers  


What is the history of c++?

0 Answers  


Can you sort a set c++?

0 Answers  


Is c++ platform dependent?

0 Answers  


Categories