100% working
void main()
{
int n,i=1,j,c;
clrscr();
printf("Enter Range To Print Prime Numbers")
scanf("%d",&n);
printf("Prime Numbers Are Following;
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d ",i)
i++;
}
getch();
}
#include<stdio.h>
void main()
{
int i, prime, lim_up, lim_low, n;
clrscr();
printf("\n\n\t ENTER THE LOWER LIMIT…: ");
scanf("%d", &lim_low);
printf("\n\n\t ENTER THE UPPER LIMIT…: ");
scanf("%d", &lim_up);
printf("\n\n\t PRIME NUMBERS ARE…: ");
for(n=lim_low+1; n<lim_up; n++)
{
prime = 1;
for(i=2; i<n; i++)
if(n%i == 0)
{
prime = 0;
break;
}
if(prime)
printf("\n\n\t\t\t%d", n);
}
getch();
}
#include<iostream>
bool is_prime (const size_t num)
{
// The first two primes are 2 and 3
switch (num)
{
case (0): case (1): return false;
case (2): case (3): return true;
}
// All even numbers > 3 are non-prime.
if (num%2==0) return false;
// Initialise a maximum divisor (the square root of num).
size_t max = (size_t) std::sqrt ((double) num);
// Add 1 if even, 2 if odd (so that max is odd).
max += (max%2) ? 2 : 1;
// Test every divisor in the half-closed range [3:max)
for (size_t div=3; div!=max; div+=2)
// Is the number evenly divisible?
if (num%div==0)
// Yes, it is non-prime.
return false;
// The number is definitely prime.
return true;
}
int main()
{
using std::cout;
cout << "Prime numbers in closed range [0:100]:\n";
for (size_t num=0; num<=100; ++num)
if (is_prime (num))
cout << num << '\n';
cout << std::endl;
}
#include<stdio.h>
#include<conio.h>
void main ()
{
int i,j,k;
clrscr();
for(i=50;i<100;i++)
{
k=1;
for(j=1;j<i;j++)
{
if(i%j==0)
{
k++;
}
}
if(k==2)
{
printf("\n %d is prime",i);
}
}
getch ();
}
#include
#include
#include
void main()
{
int i,j;
clrscr();
for(i=3;i<=1000;i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
break;
}
if(i==j)
cout<
}
getch(); // this is the easiest method to print prime nos made by Taabi
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main(int argc, char **argv)
{
int iNum,iRem,iCount=2;
printf("enter the no");
scanf("%d",&iNum);
if(iNum==1)
{
printf("The no. is not prime");
exit(0);
}
if(iNum==2)
{
printf("The no. is prime");
exit(0);
}
do
{
iRem=iNum%iCount;
if(iRem==0)
{
printf("the given no is not prime");
exit(0);
}
iCount++;
}
while(iCount<=(iNum/2));
printf("the given no is prime");
}
bool is_prime (unsigned);
for (unsigned n=1; n<=50; ++n) if (is_prime (n)) std::cout << n << " is prime" << std::endl;
You will have to implement the is_prime() function yourself. The following is a reasonably efficient but simple implementation given the narrow range of values to be considered. A larger range will require a more efficient implementation.
bool is_prime (unsigned n) {
if (n<2) return false; // 0 and 1 are not prime
if !(n%2)) return n==2; // 2 is the only even prime
// test all odd divisors from 3 up to the square root of n
unsigned max {(unsigned) std::sqrt ((double) n))};
for (unsigned div=3; div<=max; div+=2) if (!(n%div)) return false;
// if we get this far, n is prime
return true;
}
// Returns true if n is prime, false if n is composite (non-prime). bool is_prime (unsigned n) {
if (n<2) return false; // 2 is the first prime
if (!(n%2)) return n==2; // 2 is the only even prime
unsigned max = (unsigned) sqrt ((double) n); // calculate max factor
for (unsigned f=3; f<=max; f+=2) if (!(n%f)) return false; // n is composite (it has a prime factor)
return true; // n is prime
}
// Returns the next prime greater than n.
unsigned next_prime (unsigned n) {
if (n<2) return 2; // 2 is the first (and only) even prime
if (n==2) return 3; // 3 is the first odd prime
if (!(n%2))++n; else n+=2; // increment n, ensuring n is odd
while (!is_prime(n)) n+=2; // check every odd value until n is prime
return n;
}
void print_primes (unsigned max) {
unsigned n=0;
printf ("List of primes up to %u\n", max);
while ((n=next_prime (n))<=max) printf ("%u\n", n);
}
PRINT 2,3,5,7,11,13,17,19,23,29,31,37
Such a program is called a Quine. http://en.wikipedia.org/wiki/Quine_(computing)
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
#include
The print command is a way to display output to the console. The hello world program, for example, can be written in python as simply print("Hello world") Other values can also be used in a print statement: a = 4 print(a) #will print the number 4
Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.
PRINT 2,3,5,7,11,13,17,19,23,29,31,37
This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.
You can use int i; for (i = 10; i <= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.
First, create a for loop from a,1 to 50. Inside of that create another for loop b,2 to a-1. If a/b=int(a/b) then you know it is not prime
Such a program is called a Quine. http://en.wikipedia.org/wiki/Quine_(computing)
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
/*the program to print prime no from 1 to 300*/ #include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); printf("The prime numbers from 1 to 300 are\n"); for(j=2;j<=300;j++) { for(i=2;i<=j/2;i++) if(j%i==0) break; if(i>j/2) { printf("%d ",j); } } }
#include
This is a homework question and does not deserve an answer because you will learn nothing other than being lazy.
The print command is a way to display output to the console. The hello world program, for example, can be written in python as simply print("Hello world") Other values can also be used in a print statement: a = 4 print(a) #will print the number 4
Use a counted loop in the closed range [1:100]. If the count is in the closed range [40:50], print the number. For all other numbers outwith this range, only print the number if it is prime.