C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-29-2009, 06:01 AM   #1
Registered User
 
Join Date: Nov 2009
Location: Ireland
Posts: 19
assignment help. [urgent]

i am having huge problems continuing with an assignment due in four days.
Code:
#include <stdio.h>

void main()
{
	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
	
	printf("enter max factorial\n");
	scanf("%d", &i);
	printf("enter min factorial\n");
	scanf("%d", &minfactorial);	
	printf("--------------------------------------------------------------------");
	while (line<=0){
	printf("\nFactorial Value        Factorial expression            Result");
	line=line+1;
	}
	maxfactorial=i;
	factorial=i;
	while ( factorial>=minfactorial){
	printf("\n%d" ,maxfactorial);
	maxfactorial=maxfactorial-1;
	factorial=factorial-1;
	}


}
the assignment is attached and the code above is what i have got so far. any suggestions or help no matter how small would be appreciated.
Attached Files
File Type: doc DT211 1 C Programming Assignment 1.doc (38.5 KB, 32 views)
Ciaran789 is offline   Reply With Quote
Old 11-29-2009, 06:20 AM   #2
Registered User
 
rogster001's Avatar
 
Join Date: Aug 2006
Location: Liverpool UK
Posts: 553
Problem?

Considering this is urgent you have not really filled us in on the details, like what is the problem you are having? I cant be bothered going through an assignment question, just say what the issue is with code you posted
rogster001 is offline   Reply With Quote
Old 11-29-2009, 06:34 AM   #3
DESTINY
 
BEN10's Avatar
 
Join Date: Jul 2008
Location: in front of my computer
Posts: 803
Quote:
Originally Posted by Ciaran789 View Post
i am having huge problems continuing with an assignment due in four days.
Code:
#include <stdio.h>

void main()
{
	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
	
	printf("enter max factorial\n");
	scanf("%d", &i);
	printf("enter min factorial\n");
	scanf("%d", &minfactorial);	
	printf("--------------------------------------------------------------------");
	while (line<=0){
	printf("\nFactorial Value        Factorial expression            Result");
	line=line+1;
	}
	maxfactorial=i;
	factorial=i;
	while ( factorial>=minfactorial){
	printf("\n%d" ,maxfactorial);
	maxfactorial=maxfactorial-1;
	factorial=factorial-1;
	}


}
the assignment is attached and the code above is what i have got so far. any suggestions or help no matter how small would be appreciated.
To print the factorial value, just make another function which returns the factorial of maxnumber. I'm modifying your code, I dont know if it's efficient or not.
Code:
#include <stdio.h>
int fact(int num)
{
	int i,facto=1;
	for(i=1;i<=num;i++)
		facto=facto*i;
	return facto;
}int main(void)
{
	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
	
	printf("enter max factorial\n");
	scanf("%d", &i);
	printf("enter min factorial\n");
	scanf("%d", &minfactorial);	
	printf("--------------------------------------------------------------------");
	while (line<=0){
	printf("\nFactorial Value        Factorial expression            Result");
	line=line+1;
	}
	maxfactorial=i;
	factorial=i;
	while ( factorial>=minfactorial){
	printf("\n%d%60d" ,maxfactorial,fact(maxfactorial));
	maxfactorial=maxfactorial-1;
	factorial=factorial-1;
	}
return 0;
}
Always remember main returns int not void.
__________________
HOPE YOU UNDERSTAND.......

By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior


PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
BEN10 is offline   Reply With Quote
Old 11-29-2009, 07:53 AM   #4
The Beautiful C++ Utopia
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 16,515
Don't give out solutions!
Newbies learn nothing if you do it.
It is they who must learn, not us. We get nothing by simply handing out solutions except create more dumb programmers out there who do not deserve their title.
__________________
WARNING: Any and all code samples I post are not tested unless explicitly mentioned otherwise. Use at your own risk.
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
"Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff."
Quoted... at least once.
Why did the Java creators shoot themselves in the foot?
Elysia is offline   Reply With Quote
Old 11-29-2009, 08:16 AM   #5
Registered User
 
Join Date: Nov 2009
Location: Ireland
Posts: 19
thanks, i understand that bit now. one more question. do i need to use a loop to print the factorial expression?
Ciaran789 is offline   Reply With Quote
Old 11-29-2009, 08:43 AM   #6
Registered User
 
Join Date: Nov 2009
Posts: 14
Well, yes. The loop should go from the number (x from x!) down to 1.

But I don't get why you did this:
Code:
int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;

...


while (line<=0){
	printf("\nFactorial Value        Factorial expression            Result");
	line=line+1;
}
You don't need a loop if you want to do something only once.

Last edited by Junky; 11-29-2009 at 08:50 AM.
Junky is offline   Reply With Quote
Old 11-29-2009, 08:49 AM   #7
Registered User
 
Join Date: Nov 2009
Location: Ireland
Posts: 19
i put the while loop in because it was the only way i could get it to work. im not that good at programming yet.only in my first year.
Ciaran789 is offline   Reply With Quote
Old 11-29-2009, 08:52 AM   #8
The Beautiful C++ Utopia
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 16,515
Start by making a flowchart.
__________________
WARNING: Any and all code samples I post are not tested unless explicitly mentioned otherwise. Use at your own risk.
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
"Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff."
Quoted... at least once.
Why did the Java creators shoot themselves in the foot?
Elysia is offline   Reply With Quote
Old 11-29-2009, 09:16 AM   #9
Registered User
 
Join Date: Nov 2009
Posts: 14
Quote:
Originally Posted by Ciaran789 View Post
i put the while loop in because it was the only way i could get it to work. im not that good at programming yet.only in my first year.
It will work fine without the loop, you just did something else wrong.
Junky is offline   Reply With Quote
Old 11-29-2009, 09:46 AM   #10
Registered User
 
Join Date: Nov 2009
Location: Ireland
Posts: 19
thanks for the help guys.
Ciaran789 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu Krush C Programming 17 09-01-2009 02:34 AM
Assignment Operator, Memory and Scope SevenThunders C++ Programming 47 03-31-2008 06:22 AM
Screwy Linker Error - VC2005 Tonto C++ Programming 5 06-19-2007 02:39 PM
Help with a pretty big C++ assignment wakestudent988 C++ Programming 1 10-30-2006 09:46 PM
A mini-compilier I made stuck in an infinite loop (lots of code) dan06 C++ Programming 1 10-27-2006 01:21 PM


All times are GMT -6. The time now is 02:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22