Q. Display all perfect numbers below 500 [A perfect number is a number, such that the sum of its factors is equal to the number itself]. Example: 6 (1 + 2 + 3), 28 (1+2+4+7+14)
Program
#include <stdio.h>
void main()
{
int i, j, sum;
printf("All Perfect numbers between 1 to 500 :\n");
for(i=1; i<=500; i++)
{
sum = 0;
for(j=1; j<i; j++)
{
if(i % j == 0)
{
sum += j;
}
}
if(sum == i)
{
printf("%d, ", i);
}
}
}
Output:
All Perfect numbers between 1 to 500 :
6, 28, 496,
Program
#include <stdio.h>
void main()
{
int i, j, sum;
printf("All Perfect numbers between 1 to 500 :\n");
for(i=1; i<=500; i++)
{
sum = 0;
for(j=1; j<i; j++)
{
if(i % j == 0)
{
sum += j;
}
}
if(sum == i)
{
printf("%d, ", i);
}
}
}
Output:
All Perfect numbers between 1 to 500 :
6, 28, 496,


4 Comments
package com.selenium.tests;
ReplyDeleteimport 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!");
}
}
package com.selenium.tests;
ReplyDeleteimport 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();
}
}
package com.selenium.tests;
ReplyDeleteimport 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();
}
}
package com.selenium.tests;
ReplyDeleteimport 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();
}
}