![]() |
| ||
| Practise Problem, Pair of Prime Numbers Q.Write a program which will print all the pairs of prime numbers whose sum equals the number entered by the user. ( suggested by Aniseed ) (Intermediate) #include<iostream.h>Plz verify it. Any suggestions,comments or recommendations are welcomed. |
| ||
| Re: Practise Problem, Pair of Prime Numbers > #include<iostream.h> This is old. The correct form is #include <iostream> If you (or your compiler) don't know about namespaces, then it's time you looked into it, or upgraded your compiler. namespaces have been standard issue since 1998, so there's really no excuse any more. > #include<conio.h> This is non-standard. If you can write your code without it, do so. > #include<math.h> In a namespace enabled compiler, this would be #include <cmath> > void main() This is just wrong. main returns an int. Your prime() function could be more efficient, especially for large numbers. How many even primes are there? |
| ||
| Re: Practise Problem, Pair of Prime Numbers Salem's post is just OK. Things that I more wanna say that if you write #include<iostream> then you must write "using namespace std;" next line & you can use #include<cmath> in place of #include<math.h>. That's all. |
| ||
| Re: Practise Problem, Pair of Prime Numbers I know about namespaces and the new standards i.e #include<iostream> , but ya my compiler "Turbo C++ v3.0" is old and dont understands the new formats like namespaces and the new style header files. An upgraded, according to the new standards, code will be #include<iostream>And thanks Salem and hiraksarkardg for your concern. :) Is conio.h not ISO C++ standard. Which funtion to be used in place of clrscr() and getch()? |
| ||
| Re: Practise Problem, Pair of Prime Numbers > Is conio.h not ISO C++ standard. Correct. > Which funtion to be used in place of clrscr() and getch()? Such things only matter (to some extent) when you're running from the IDE. Most programs have neither. Consider 'dir', which neither clears the screen, nor waits for a key press. |
| ||
| Re: Practise Problem, Pair of Prime Numbers Why void main is deprecated in ISO standards? Where can i get a brief overview of the ISO C++ standards? |
| ||
| Re: Practise Problem, Pair of Prime Numbers You can't deprecate what was never standard to begin with. void main has always been wrong, despite what many popular books and sloppy compilers say or do |
| ||
| Re: Practise Problem, Pair of Prime Numbers Thanks Salem for help, I think you really hate those who use "void main()" and you love "int main()" as your avtar and line under name says :D |
| ||
| Re: Practise Problem, Pair of Prime Numbers Any other tips for efficiency? There is only 1 even prime number i.e 2. |
| ||
| Re: Practise Problem, Pair of Prime Numbers >>There is only 1 even prime number i.e 2 So, is there a simple way to determine if a number is even or odd? And, if any factor above 2 is even can the number be prime? This might be a little more optimized: bool isprime(int a) |
| All times are GMT -4. The time now is 3:41 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC