GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Dec-2007, 19:56
vannurbasha vannurbasha is offline
New Member
 
Join Date: Dec 2007
Posts: 3
vannurbasha is on a distinguished road
Unhappy

Programme for b/w two prime numbers


i want programe r code b/w two prime numbers
Ex:1 to 19 prime numbers with the code r programe .............
  #2  
Old 07-Dec-2007, 08:25
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: programe for b/w two prime numbers


I can't really tell what you're asking, but it looks like you want to write a program that inputs 2 numbers and prints every prime number in between them (inclusive). Is that correct? If so, here is a little template for you to start with:

CPP / C++ / C Code:
// This function prints out all of the prime numbers between A and B
void PrintPrimes( int A, int B )
{ int i;

  // Make sure A is less than B 
  if( A > B )
  { // Swap them
    i = A;
    A = B;
    B = i;
  }

  for(i=A;i<=B;i++)
  { if(/* i is a prime number */) printf("%d\n",i);
  }
}

int main()
{ int Num1,Num2;
  
  // Get user input  
  printf("Enter the first number: ");
  scanf("%d",&Num1);
  printf("\nEnter the second number: ");
  scanf("%d",&Num2);

  // Call a function to print the prime numbers in between 
  PrintPrimes( Num1, Num2 );
  
  return 0;
} 

Now, all you have to do is write the function that will tell you if an integer is a prime number or not.
  #3  
Old 07-Dec-2007, 09:09
vannurbasha vannurbasha is offline
New Member
 
Join Date: Dec 2007
Posts: 3
vannurbasha is on a distinguished road

Re: programe to display all prime numbers in b/w given two numbers


CPP / C++ / C Code:
void main()
{
 int i,a,b;
 printf("enter the numbers")
 scanf("%d%d",&a,&b);
 if(a<b)
  {
    for(i=a;i<=b;i++)
    {
      if(a%2==0)
      {
        printf('is not a prime number");
        break;
      }
     a++;
   }
  if(i==a)
   {
     printf("is a prime number");
   }
}

take example as a=1 and b=20 and what's wrong in the programme can you tell please it display the error and tell me the correct code/programme
Last edited by admin : 07-Dec-2007 at 09:29. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #4  
Old 07-Dec-2007, 09:29
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: programe for b/w two prime numbers


My guess is that the line:

printf('is not a prime number");

is giving you an error. Try replacing it with:

printf("is not a prime number");

Other than that, it probably won't work. If I were you, I would follow the example that I posted. When you break processes down into functions, it makes it a lot easier to debug.

Start by creating a function that returns a boolean as to whether a number is prime or not. Something like:

CPP / C++ / C Code:
// Returns non-zero if prime, zero if not prime
int IsPrime( int N )
{ // You fill in this section. 
}

Then, you should test just this function by itself before putting it in with the rest of the code.
  #5  
Old 05-May-2008, 23:53
maryam maryam is offline
New Member
 
Join Date: May 2008
Posts: 2
maryam is on a distinguished road
Red face

Re: Programme to display prime numbers 1 - 20


please send me a complete codo of programme how to display prime numbers from 1 to 20
  #6  
Old 05-May-2008, 23:59
maryam maryam is offline
New Member
 
Join Date: May 2008
Posts: 2
maryam is on a distinguished road

Re: Programme for b/w two prime numbers


#include<iostream>
using namespace std;
void main()
{
int w,x,y,z;
for(x=2;w<=20;x++)
z=0;
{
for(y=2;y<=x-i;y++)
if(x%y==0)
cout<<"z++";
}
if(z==0)
cout<<"x";
}
  #7  
Old 06-May-2008, 07:34
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Programme for b/w two prime numbers


For another example, see this thread.
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Will pay through Paypal if somebody helps me. paritoshcool Assembly Language 0 27-Nov-2007 22:27
prime numbers hiflya69 CPP / C++ Forum 5 19-Oct-2007 20:42
Table killer9012 CPP / C++ Forum 29 10-Oct-2006 21:15
Python script: Prime numbers crystalattice Python Forum 4 16-Apr-2006 08:19
prime numbers quasimof CPP / C++ Forum 1 01-Nov-2004 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:26.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.