C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 13th, 2005, 05:25 AM
anubis anubis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 anubis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 47 sec
Reputation Power: 0
Angry Top Down Design help

I have a problem with my program. The program is find if a number is perfect for eg 6 is perfect since 1+2+3=6
. Well the program has to determine if a single number passed as perfect. The funtion should return 1 if it is n a 0 if not. Call this program function from the main program for each of the number from 1 to 1000. The main program should print out each of the perfect numbers on seperate lines.
This is wat i got so far


Code:
 #include<stdio.h> 
#include<conio.h>
int perfect(int num,int perfect1,int perfect2,int perfect3,int perfect4,int perfect5,int perfect6);
void main()
{
int num,prfct;
printf("enter a number: ");
scanf("%d",&num);
prfct=perfect(num);
printf("Perfect is: %d",num);
n1=perfect(perfect1);
n2=perfect(perfect2);
n3=perfect(perfect3);
n4=perfect(perfect4);
n5=perfect(perfect5);
n6=perfect(perfect6);
printf("The perfect numbers are: \n%d\n",n1);
printf("%d\n",n2);
printf("%d\n",n3);
printf("%d\n",n4);
printf("%d\n",n5);
printf("%d\n",n6);
getch();
}
int perfect(int num,int perfect1,int perfect2,int perfect3,int perfect4,int perfect5,int perfect6)
{
int prfctcnt=0;
if(num<=1000 && num<2)
{
num=num-1;
if(num%2==0)
prfctcnt++;
prfctcnt++;

Do u need how to do programming to be a godd electronic engineer

Reply With Quote
  #2  
Old April 13th, 2005, 04:57 PM
BoolBooB BoolBooB is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 36 BoolBooB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 35 m 42 sec
Reputation Power: 4
Frist, most EE's will end up as Software Engineers (there are just WAY more SW opportunities out there than hardware) so yes, being a good programmer will help.

Second, what does this have to do with top down design? I hope you aren't bothering to learn top down design, that was outdated 15+ years ago.

Code:
 
for (int i = 1; i <= 1000; i++) {
	if (isperfedt(i)) {
		cout << "i " << is perfect << endl;
	}
}
 
...
 
bool isperfect(int i) {
 
	int x;
	x = 1;
	int perfection;
	perfection = 0;
	
	do {
		perfection += x;
		if (perfection == i) return true;
		++x;
	} while (perfection < i)
	return false
}
		

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Top Down Design


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT