0
Write a programme in C++ that computes and displays a factorial of a number.
In c++
5 Antworten
+ 4
why?
+ 3
+ 2
#include<iostream.h>
#include<conio.h>
void main()
{
int x; //The required number to be entered by the user.
int product=1; //The required result.
cout<<"Welcome user, enter the number of your desire to find its factorial=";
cin>>x;
if(x>0)
for(int i=x;i>0;i--)
{
product*=i;
}
else
product=1;
cout<<"The requested number="<<x;
cout<<x;
for(i=x-1;i>0;i--)
{
cout<<"X"<<i;
}
cout<<"\nThe desired factorial="<<product;
cout<<"\n\n\t\tTHANK YOU FOR USING MY PROGRAM(VARUN SINGH)";
getch();
}
here you go bro.
+ 1
@Abhishek Shrivastava :Yes, you are correct bro,its just that i forgot to copy my corrected code and posted this one..
About using outdated compilers/c style coding. I'am much more comfortable in it also that i just started learning c++ so i dont know much and my teacher even didnt responded to most of my queries so here iam with such a style of coding.
0
@Varun Singh : Should there be <<x only after "The requested number=" because you have used cout<<x just after it and also a for loop is there to represent the factorial in expanded from. I think that should be cout<<"The requested number=" <<x<<"!\n="
And one more thing.... Why you still prefer C style of coding using outdated compilers or IDEs ?