#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int l;
float i,sum=1,j,k,x=0,n;
cout<<"Enter last limit:";
cin>>n;
l=n;
for(i=0;i<n;i++,l--)
{
for (k=1,sum=1; k<= l; k++ )
sum =sum* k;
x=x+(1/sum);
}
cout<<x+1;
getch();
}
P.S. A good programming practice, nowadays we don't need clrscr();
So, avoid it where you can.
^^ you don't need to clear the screen with the newer IDEs and compilers. Still you can do so by using system("cls") function. (in Windows). also as conio.h has been deprecated, clrscr() shouldnt be used.
also for the sake of your knowledge, algo for calculating consecutive factorials can be made very fast and efficient using dynamic programming. (in easy words, storing the results of a smaller problem and not calculating it again and again). give a thought to it.![]()
*So does that mean that newer IDEs or compilers elf implement clrscr functionality?
*this system("cls") function is for c++ na? its syntax pls ( i couldnt get it actually )
*Do you mean "discontinued" by "deprecated". Plus, yeah, i have read somewhere that conio.h has been 'deprecated' Why so and any additions resulting after its deprecation?
*Do u refer to DMA by dynamic programming ?
Thnx for answering my queries, and for sure i'll give them a serious thought![]()
*new compilers, atleast the standard g++ don't support conio.h which has clrscr().
* system() function executes any command the OS supports. eg. if you type cls in command line in windows, the screen will be cleared. to perform this in C++, use system("cls");. you can change the argument of system to do anything else like executing an external program.
* deprecated means it will be discontinued in near future. it has already been removed from g++ and exists only in old compilers. I think minGw gives a warning for conio.h. conio.h is basically for old DOS compilers and doesnt serve any purpose nowadays.
* no.
Dynamic programming - Wikipedia, the free encyclopedia
Why would you need to clear the screen before running your program?