The task is to create a program that can do the maximum factorial possible by the machine using "for" cycle.
I understood i have to use bigger data types (the biggest one is "long long", correct me if i'm wrong), and i also understood the concept of the factorial.
Otherwise, i really do not know how to apply what i know in c++.
these is the idea at the base of what i wrote down as of now:
#include <cstdlib>
#include <iostream>
#include <math.h>
include namespace std;
int main(int argc, char *argv[])
{
long long i, factorial;
cin<<factorial;
{
for(long long i=1; i=factorial; i++)
{
factorial=factorial*i
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Problems are:
- I don't know if the code it's wrote correctly
- by doing "factorial=factorial*i", the "i=factorial" in the "for" cycle doesn't make sense, since it will stop the program before it has to.
This being said, I would like to point out that i am in high school, my programming knowledge is really poor, and for this reason every kind of advice and information is very well accepted :).
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire