Both code are exactly same but give different output

//this is 1st program

#include
using namespace std;

int main(){
cout <<“Enter a positive number:”;
int number;
cin >> number;

if (number<0)
cout <<"Error!, Enter a positive number.";

else{
    int factorial = 1;
    for(int i = 1; i<=number; i++)
    factorial*=1;
    cout << "The factorial of" << number << ':'<< factorial;
    return 0;
}

}

// this is 2nd program

#include
using namespace std;

int main(){
cout <<“Enter a positive number:”;
int number;
cin >> number;

if (number<0)
cout <<"Error!, Enter a positive number.";

else{
    int factorial = 1;
    for(int i = 1; i<=number; i++)
    factorial*=i;
    cout << "The factorial of" << number << ':'<< factorial;
    return 0;
}

}

// i did not understand why bot give different output. please explain me.

Look for // different in second program.

1 Like