write the program for prime numbers?
Answer Posted / mamoon
#include<iostream.h>
#include <math.h>
void main()
{
int number;
cout<<" --------------------------------------------
-"<<endl;
cout<<" Enter a number to find if its a prime
number "<<endl;
cout<<" --------------------------------------------
-"<<endl;
cin>>number;
bool a =true;
for(int i=2;i<sqrt(number);i++) //check
untill the square root
{
if(number%i==0) // if it is
divisible it is non prime
{
a=false;
break;
}
}
if(a==false)
cout<<number<<" \nis not a prime number"<<endl;
else
cout<<number<<" \nis a prime number"<<endl;
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Multiply an Integer Number by 2 Without Using Multiplication Operator
How can I recover the file name given an open stream?
#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }
while initialization of array why we use a[][2] why not a[2][]...?
Hai what is the different types of versions and their differences
struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer
What are loops c?
What are header files in c programming?
What is the benefit of using const for declaring constants?
What are the differences between Structures and Arrays?
Write a program of prime number using recursion.
What do header files do?
what is the role you expect in software industry?
What is a header file?
How can you find the day of the week given the date?