int main()
{
printf("Enter 0 or 1 :");
scanf("%d",&i_choice);

  if ( i_choice ==0 )
  for(	;i_count_1 < i_number;)
  {-------
   ------
  }
  
  if (choice == 1)
  for(	;i <= i_number;)
  {-------
  ------
  }

Here I raed a user input ( 0 or 1)
So as per i/p I've to change the condition in my for loop.
if choice ==1 the condition must be (i <= i_number)
if choice == 0 the condition must be (i_count_1 < i_number)

I don't know how to use #define with this program.

anybody can help me....
Krish

Salem commented: 20+ posts, and code still looks like crap WITHOUT THE F***ING CODE TAGS! -4
xavier666 commented: I gotta find a compiler which can compile emoticons! +0

Recommended Answers

All 3 Replies

#define i_choice 0
or
#define choice 1

int main() {


}

I don't know how to use #define with this program.

Question is, why do you want to use #define in your program?

Okkk... I realize I can't use a #define here....
becoz I am getting choice inside a function...

But my code is repeating twice ...I wanna avoid that....
Except condition the other statements are same for both...

Here is my code

printf("\n U wanna find prime nos up to N(press 1)
or N prime nos (press 0 ");
scanf("%d",&i_choice);

switch(i_choice) {

case 0 :
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 :
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++;
}
}
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.