im trying to write a program for factorial of a number( 3 here), but its only calculating the last number in the loop ( 3 here) instead of calculating both 2 and 3. can some one please tell me whats wrong in the code.
using namespace std;
int x ,y;
x = 1; // Point 1
Point 1 : If you initialize x to zero, any multiplication done with x will always be 0.. Also, since x is to hold the result of 3!, it doesnt need to be initialized to 3.. if you do that< then you would be calculating (3*3)(3*2)(3*1).
Point 2: Your while loop did not encompass the code that was to be looped.. That was why only the last number in the loop was calculated..