Q. write a program to print all the prime numbers between 1 to 100.
Sir, i hv written a code for this but it is not working. below shown is my code
#include<iostream.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for (i=0;i<100;i++)
{
if (i%2!=0&&i%3!=0)
{
cout<<i;
}
}
getch();
}
using namespace std; //function check if number is prime bool IsPrime(int number) { if ((number & 1) == 0) { if (number == 2) { return true; } else { return false; } } for (int i = 3; (i * i) <= number; i += 2) { if ((number % i) == 0) { return false; } } return number != 1; } //main function int main() {
for(int i=2;i<=1000;i++){ bool prime = IsPrime(i); if (prime){ cout<<i<<" Prime "; } } cout<<"Press any key to exit..."; getch(); return 0; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment