Skip to main content
simplify title, and spelling of comparisions
Source Link
rolfl
  • 97.5k
  • 17
  • 218
  • 418

Program to find the Finding prime numbers between two given integers in the minimum number of comparisionsa range

Finding the prime numbers between two given integers in the minimum number of comparisons:

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
    clrscr();
    int i,n,count,n1,n2;
    printf("Enter n1 and n2:");
    scanf("%d",&n1);
    scanf("%d",&n2);
    n=n1;
    int c=0; //variable to store number of comparisions (number of times while() runs)
    for(n=n1;n<=n2;n1++,n=n1)
    {
        count=0; //number of factors found
        i=2;
        while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
        {
            printf("\n\t%d",c++);//printing the comparision number
            if(n%i==0)
            {
                count++;
                n/=i;
            }
            else i++;
        }
        if(count==0)
            printf("\n%d",n1);
    }
    getch();
}

Program to find the prime numbers between two given integers in the minimum number of comparisions

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
    clrscr();
    int i,n,count,n1,n2;
    printf("Enter n1 and n2:");
    scanf("%d",&n1);
    scanf("%d",&n2);
    n=n1;
    int c=0; //variable to store number of comparisions (number of times while() runs)
    for(n=n1;n<=n2;n1++,n=n1)
    {
        count=0; //number of factors found
        i=2;
        while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
        {
            printf("\n\t%d",c++);//printing the comparision number
            if(n%i==0)
            {
                count++;
                n/=i;
            }
            else i++;
        }
        if(count==0)
            printf("\n%d",n1);
    }
    getch();
}

Finding prime numbers in a range

Finding the prime numbers between two given integers in the minimum number of comparisons:

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
    clrscr();
    int i,n,count,n1,n2;
    printf("Enter n1 and n2:");
    scanf("%d",&n1);
    scanf("%d",&n2);
    n=n1;
    int c=0; //variable to store number of comparisions (number of times while() runs)
    for(n=n1;n<=n2;n1++,n=n1)
    {
        count=0; //number of factors found
        i=2;
        while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
        {
            printf("\n\t%d",c++);//printing the comparision number
            if(n%i==0)
            {
                count++;
                n/=i;
            }
            else i++;
        }
        if(count==0)
            printf("\n%d",n1);
    }
    getch();
}
Tweeted twitter.com/#!/StackCodeReview/status/493014121894658048
rearranged tags, formatted code
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282
#include<stdio#include <stdio.h>
#include<conio#include <conio.h>
#include<math#include <math.h>

void main()
{
    clrscr();
    int i,n,count,n1,n2;
    printf("Enter n1 and n2:");
    scanf("%d",&n1);
    scanf("%d",&n2);
    n=n1;
    int c=0; //variable to store number of comparisions (number of times while() runs)
    for(n=n1;n<=n2;n1++,n=n1)
    {
        count=0; //number of factors found
        i=2;
        while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
        {
            printf("\n\t%d",c++);//printing the comparision number
            if(n%i==0)
            {
                count++;
                n/=i;
            }
            else i++;
        }
        if(count==0)
            printf("\n%d",n1);
    }
    getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
int i,n,count,n1,n2;
printf("Enter n1 and n2:");
scanf("%d",&n1);
scanf("%d",&n2);
n=n1;
int c=0; //variable to store number of comparisions (number of times while() runs)
for(n=n1;n<=n2;n1++,n=n1)
{
    count=0; //number of factors found
    i=2;
    while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
    {
        printf("\n\t%d",c++);//printing the comparision number
        if(n%i==0)
        {
            count++;
            n/=i;
        }
        else i++;
    }
    if(count==0)
    printf("\n%d",n1);
}
getch();
}
#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
    clrscr();
    int i,n,count,n1,n2;
    printf("Enter n1 and n2:");
    scanf("%d",&n1);
    scanf("%d",&n2);
    n=n1;
    int c=0; //variable to store number of comparisions (number of times while() runs)
    for(n=n1;n<=n2;n1++,n=n1)
    {
        count=0; //number of factors found
        i=2;
        while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
        {
            printf("\n\t%d",c++);//printing the comparision number
            if(n%i==0)
            {
                count++;
                n/=i;
            }
            else i++;
        }
        if(count==0)
            printf("\n%d",n1);
    }
    getch();
}
Source Link

Program to find the prime numbers between two given integers in the minimum number of comparisions

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
int i,n,count,n1,n2;
printf("Enter n1 and n2:");
scanf("%d",&n1);
scanf("%d",&n2);
n=n1;
int c=0; //variable to store number of comparisions (number of times while() runs)
for(n=n1;n<=n2;n1++,n=n1)
{
    count=0; //number of factors found
    i=2;
    while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
    {
        printf("\n\t%d",c++);//printing the comparision number
        if(n%i==0)
        {
            count++;
            n/=i;
        }
        else i++;
    }
    if(count==0)
    printf("\n%d",n1);
}
getch();
}