Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 19-09-2011, 06:26 PM   #1 (permalink)
Night Fury
 
mayoorite's Avatar
 
Join Date: Jun 2011
Location: Ajmer,Rajasthan
Posts: 99
Question c++ programming in making n!


1+1/1!+1/2!.....n
I got really confused in this
please help today
mayoorite is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 19-09-2011, 07:26 PM   #2 (permalink)
Neo
Alpha Geek
 
Neo's Avatar
 
Join Date: Jun 2011
Location: Near my Computer.
Posts: 507
Default Re: c++ programming in making n!

what to make?
clarify please
Neo is offline  
Old 20-09-2011, 01:40 AM   #3 (permalink)
I'm a Wannabe Hacker
 
Prime_Coder's Avatar
 
Join Date: Apr 2011
Location: Oxford of D East!
Posts: 235
Default Re: c++ programming in making n!

Question not clearly mentioned. You should mention it and please use brackets, if possible.
Prime_Coder is offline  
Old 20-09-2011, 01:28 PM   #4 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default Re: c++ programming in making n!

1. Create a recursive function for calculating n!
2. In a "for" loop, keep adding the result of 1/i! for i varying from 1 to n
3. Output the result.

Which portion of this has you confused?

Arun
sakumar79 is offline  
Old 20-09-2011, 03:04 PM   #5 (permalink)
Right Off the Assembly Line
 
Join Date: Sep 2011
Posts: 23
Default Re: c++ programming in making n!

Code:
#include <iostream.h>
#include <conio.h>

void main()
{
int sum=0,i,n;
int nfact=1;
for(i=1;i<=n;i++)
{
nfact=nfact*i
sum = sum + 1/nfact
}
cout<<"Sum is : "<<sum;
getch();
}
Windows is offline  
Old 20-09-2011, 09:41 PM   #6 (permalink)
Night Fury
 
mayoorite's Avatar
 
Join Date: Jun 2011
Location: Ajmer,Rajasthan
Posts: 99
Cool Re: c++ programming in making n!

thanks for response well i have done it.
Code:
#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();
}
mayoorite is offline  
Old 20-09-2011, 10:26 PM   #7 (permalink)
BMG ftw!!
 
d6bmg's Avatar
 
Join Date: Aug 2011
Location: Kolkata
Posts: 3,815
Default Re: c++ programming in making n!

P.S. A good programming practice, nowadays we don't need clrscr();
So, avoid it where you can.
d6bmg is offline  
Old 21-09-2011, 02:47 AM   #8 (permalink)
Off for a while.
 
dashing.sujay's Avatar
 
Join Date: Nov 2009
Location: Bhopal
Posts: 2,644
Default Re: c++ programming in making n!

Quote:
Originally Posted by d6bmg View Post
P.S. A good programming practice, nowadays we don't need clrscr();
So, avoid it where you can.
Why so ? Any new command instead of it?
__________________
Sony Vaio CB35-> i5-2430M | 6630M | 4GB | 1080p | Backlit Keyboard

Read before asking / messaging any moderator for any query: FAQ + answers for new members

Drop Box: Get 500MB free

dashing.sujay is online now  
Old 21-09-2011, 12:44 PM   #9 (permalink)
BIOS Terminator
 
nims11's Avatar
 
Join Date: Apr 2008
Location: Ranchi
Posts: 816
Default Re: c++ programming in making n!

^^ 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.
nims11 is online now  
Old 21-09-2011, 01:01 PM   #10 (permalink)
Off for a while.
 
dashing.sujay's Avatar
 
Join Date: Nov 2009
Location: Bhopal
Posts: 2,644
Default Re: c++ programming in making n!

Quote:
Originally Posted by nims11 View Post
^^ 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
__________________
Sony Vaio CB35-> i5-2430M | 6630M | 4GB | 1080p | Backlit Keyboard

Read before asking / messaging any moderator for any query: FAQ + answers for new members

Drop Box: Get 500MB free

dashing.sujay is online now  
Old 21-09-2011, 05:00 PM   #11 (permalink)
BIOS Terminator
 
nims11's Avatar
 
Join Date: Apr 2008
Location: Ranchi
Posts: 816
Default Re: c++ programming in making n!

Quote:
Originally Posted by dashing.sujay View Post
*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
nims11 is online now  
Old 21-09-2011, 05:28 PM   #12 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: c++ programming in making n!

Why would you need to clear the screen before running your program?

For example, if I am working on command line, executed some other commands and then invoked the program, it will clear my screen; which normally not the intended behavior.

And if in some rare cases, you still need to clear the screen, as nims11 mentioned, you can use system() call.
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 21-09-2011, 06:30 PM   #13 (permalink)
Alpha Geek
 
Join Date: Jan 2007
Location: In your hearts
Posts: 828
Default Re: c++ programming in making n!

once again a Turbo user!!
abhijangda is online now  
Old 21-09-2011, 07:31 PM   #14 (permalink)
Off for a while.
 
dashing.sujay's Avatar
 
Join Date: Nov 2009
Location: Bhopal
Posts: 2,644
Default Re: c++ programming in making n!

Quote:
Originally Posted by nims11 View Post
*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
Thnx, got all points.

Queries- *Since conio.h is no longer continued, so is getch() ? If yes, then what is the replacement for it? And what about other functions needing conio.h ?
*So, turboC comes in those "old DOS compilers" ? Should i not use it ? If yes, then should i use MS VC++ ?

Quote:
Originally Posted by Garbage View Post
Why would you need to clear the screen before running your program?
Just to look neat and clean
__________________
Sony Vaio CB35-> i5-2430M | 6630M | 4GB | 1080p | Backlit Keyboard

Read before asking / messaging any moderator for any query: FAQ + answers for new members

Drop Box: Get 500MB free

dashing.sujay is online now  
Old 21-09-2011, 07:48 PM   #15 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: c++ programming in making n!

Please take further discussion to one of the two C/C++ stickies as fit.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:34 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2