C Program to Display Prime Numbers Between Two Intervals - IProgramX

Q. Write a program to display all prime numbers between ____ and ____.


Program

#include <stdio.h>
int main()
{
    int low, high, i, flag,x;
    printf("Enter two numbers : ");
    scanf("%d %d", &low, &high);
    if(low>high)
    {
     x=high;
     high=low;
     low=x;
}
    printf("Prime numbers between %d and %d are: ", low, high);
    while (low < high)
    {
        flag = 0;

        for(i = 2; i <= low/2; ++i)
        {
            if(low % i == 0)
            {
                flag = 1;
                break;
            }
        }

        if (flag == 0)
            printf("%d ", low);
        ++low;
    }
}

Output:

Enter two numbers : 2 10
Prime numbers between 2 and 10 are: 2 3 5 7

Post a Comment

6 Comments

  1. <dependencies
    <dependency
    <groupId org.seleniumhq.selenium</groupId
    <artifactId selenium-java</artifactId
    <version 4.44.0</version
    </dependency

    <dependency
    <groupId io.github.bonigarcia</groupId
    <artifactId webdrivermanager</artifactId
    <version 6.3.4</version
    </dependency
    </dependencies

    ReplyDelete
  2. Launch_test : Launch browser and URL


    package com.selenium.tests;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class Launch_test {
    public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.redbus.in/");
    driver.manage().window().maximize();
    System.out.println("Launch URL Successfully!");
    }
    }

    ReplyDelete
  3. Login_Test : Locate Element by ID & name




    package com.selenium.tests;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class Login_Test {
    public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new ChromeDriver();

    driver.get("https://practicetestautomation.com/practice-test-login/");
    driver.manage().window().maximize();

    WebElement username = driver.findElement(By.id("username"));
    username.sendKeys("student");
    Thread.sleep(3000);

    WebElement password = driver.findElement(By.name("password"));
    password.sendKeys("Password123");
    Thread.sleep(3000);

    WebElement login = driver.findElement(By.id("submit"));
    login.click();
    Thread.sleep(3000);

    System.out.println("Title: " + driver.getTitle());
    Thread.sleep(3000);

    driver.quit();
    }
    }

    ReplyDelete
  4. NavigationTest : Navigation Comands




    package com.selenium.tests;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class NavigationTest {

    public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new ChromeDriver();

    driver.get("https://www.google.com/");
    System.out.println("Open Google");

    Thread.sleep(2000);

    driver.navigate().to("https://github.com/");
    System.out.println("Open Github");

    Thread.sleep(2000);

    driver.navigate().back();
    System.out.println("Navigation Back");

    Thread.sleep(2000);

    driver.navigate().forward();
    System.out.println("Navigation Forward");

    Thread.sleep(2000);

    driver.navigate().refresh();
    System.out.println("Navigation Refresh");

    Thread.sleep(3000);

    driver.quit();
    }
    }

    ReplyDelete
  5. Locator_Test : locate element by class name, tag name and link



    package com.selenium.tests;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class Locator_Test {
    public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("https://www.google.com/");

    WebElement element1 = driver.findElement(By.className("gLFyf"));
    element1.sendKeys("Selenium Testing");
    System.out.println("Text entered Successfully");

    WebElement element2 = driver.findElement(By.tagName("input"));
    System.out.println("TagName Text:" + element2.getTagName());

    WebElement element3 = driver.findElement(By.linkText("Gmail"));
    System.out.println("Link Text:" + element3.getText());
    element3.click();

    Thread.sleep(5000);
    driver.quit();
    }
    }

    ReplyDelete
  6. cssSelector_Test : CSS selector



    package com.selenium.tests;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class cssSelector_Test {
    public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new ChromeDriver();
    driver.get("https://www.google.com/");
    driver.manage().window().maximize();

    WebElement searchBox = driver.findElement(By.cssSelector("textarea.gLFyf"));
    searchBox.sendKeys("Selenium Testing");
    System.out.println("Text Entered Successfully");

    Thread.sleep(3000);
    System.out.println("Title: " + driver.getTitle());
    System.out.println("Current URL: " + driver.getCurrentUrl());

    driver.quit();
    }
    }

    ReplyDelete