Click here to Skip to main content
15,887,411 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionBalloonToolTip [modified] Pin
S p k 52130-Dec-09 16:41
S p k 52130-Dec-09 16:41 
Question#define how to use with is code ? Pin
krish_kumar30-Dec-09 15:56
krish_kumar30-Dec-09 15:56 
AnswerRe: #define how to use with is code ? Pin
Maxwell Chen30-Dec-09 16:16
Maxwell Chen30-Dec-09 16:16 
GeneralRe: #define how to use with is code ? Pin
krish_kumar30-Dec-09 16:30
krish_kumar30-Dec-09 16:30 
GeneralRe: #define how to use with is code ? Pin
Maxwell Chen30-Dec-09 16:36
Maxwell Chen30-Dec-09 16:36 
GeneralRe: #define how to use with is code ? Pin
David Crow30-Dec-09 17:12
David Crow30-Dec-09 17:12 
GeneralRe: #define how to use with is code ? Pin
krish_kumar30-Dec-09 18:17
krish_kumar30-Dec-09 18:17 
GeneralRe: #define how to use with is code ? Pin
Maxwell Chen30-Dec-09 19:46
Maxwell Chen30-Dec-09 19:46 
I would suggest you to re-design your code architecture. See the sample code below.

#include <iostream>

int GetNextPrime(int iStartNum)
{
	int i, j;
	int i_count;
	for(i = iStartNum; ; i++) {
		for(j = 1, i_count = 0; j <= i ; j++) {
			if( (i % j) == 0 )
				++i_count;
		}
		if(i_count <= 2) {
			return i;
		}
	}
	return 0;
}

void main()
{
	int i_choice;
	int i_count;
	int i_count_1 = 0;
	int i_number = 10;
	int i, j;
	int iValNow;
	int count;

	printf("Find prime nos up to %d (press 1), or %d prime nos (press 0) ", i_number, i_number);
	scanf("%d", &i_choice);


	// ---------------------------------------------------------
	printf("\n My version: \n");
	switch(i_choice)
	{
	case 0 :	// N count.
		for(i = 0, iValNow = i, count = 0; count < i_number; i++, count++) {
			iValNow = GetNextPrime(iValNow +1);
			printf("\t %d \n", iValNow);			
		}
		break;
	case 1 :	// up to N.
		for(iValNow = 0; ; ) {
			iValNow = GetNextPrime(iValNow +1);
			if(iValNow > i_number) {
				break;
			}
			printf("\t %d \n", iValNow);
		}
		break;
	}

	// ---------------------------------------------------------
	printf("\n Your version: \n");

	switch(i_choice)
	{
	case 0 :	// N count.
		for(i = 1, i_count = 0; i_count_1 < i_number; i++ ) {
			for(j = 1,i_count = 0; j <= i ; j++) {
				if( (i % j) == 0 )
					++i_count;
			}
			if(i_count <= 2) {
				printf("\t %d \n",i);
				i_count_1++;
			}
		}
		break;

	case 1 :	// up to N.
		for(i = 1, i_count = 0 ; i <= i_number; i++ ) {
			for(j = 1, i_count = 0; j <= i ; j++) {
				if( (i % j) == 0 )
					++i_count;
			}
			if(i_count <= 2) {
				printf("\t %d \n",i);
				i_count_1++;
			}
		}
	}
}


  Maxwell Chen

AnswerRe: #define how to use with is code ? Pin
David Crow31-Dec-09 8:44
David Crow31-Dec-09 8:44 
Questionlibrary linking error Pin
noalias___30-Dec-09 11:44
noalias___30-Dec-09 11:44 
AnswerRe: library linking error Pin
Migounette30-Dec-09 13:12
Migounette30-Dec-09 13:12 
GeneralRe: library linking error Pin
noalias___31-Dec-09 6:13
noalias___31-Dec-09 6:13 
QuestionJust a minor KMDF concern Pin
Mattzimmerer30-Dec-09 10:47
Mattzimmerer30-Dec-09 10:47 
AnswerRe: Just a minor KMDF concern Pin
JudyL_MD30-Dec-09 11:10
JudyL_MD30-Dec-09 11:10 
QuestionIs there any way to execute XQuery through MFC or C++ (This question Previously left with no answer) Pin
A&Ms30-Dec-09 8:21
A&Ms30-Dec-09 8:21 
QuestionRe: Is there any way to execute XQuery through MFC or C++ (This question Previously left with no answer) Pin
David Crow30-Dec-09 9:40
David Crow30-Dec-09 9:40 
JokeRe: Is there any way to execute XQuery through MFC or C++ (This question Previously left with no answer) Pin
enhzflep30-Dec-09 12:00
enhzflep30-Dec-09 12:00 
GeneralRe: Is there any way to execute XQuery through MFC or C++ (This question Previously left with no answer) Pin
Tim Craig30-Dec-09 19:59
Tim Craig30-Dec-09 19:59 
AnswerRe: Is there any way to execute XQuery through MFC or C++ (This question Previously left with no answer) Pin
A&Ms31-Dec-09 0:20
A&Ms31-Dec-09 0:20 
QuestionPipe & Fork code - need help Pin
SummerBulb30-Dec-09 7:24
SummerBulb30-Dec-09 7:24 
AnswerRe: Pipe & Fork code - need help Pin
CPallini30-Dec-09 8:02
mveCPallini30-Dec-09 8:02 
QuestionRe: Pipe & Fork code - need help Pin
SummerBulb30-Dec-09 8:14
SummerBulb30-Dec-09 8:14 
AnswerRe: Pipe & Fork code - need help Pin
CPallini30-Dec-09 9:57
mveCPallini30-Dec-09 9:57 
QuestionRe: Pipe & Fork code - need help Pin
SummerBulb30-Dec-09 19:44
SummerBulb30-Dec-09 19:44 
AnswerRe: Pipe & Fork code - need help Pin
CPallini30-Dec-09 22:02
mveCPallini30-Dec-09 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.