Spirituality what is the javascript program for product of first 10 prime numbers

what is the javascript program for product of first 10 prime numbers

javascript
Copy code
// Define a function to check if a number is prime
function isPrime(n) {
if (n < 2) {
return false;
}
for (let i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) {
return false;
}
}
return true;
}

// Initialize variables
let product = 1;
let count = 0;
let num = 2;

// Loop through the first 10 prime numbers
while (count < 10) {
if (isPrime(num)) {
product *= num;
count++;
}
num++;
}

// Print the product of the first 10 prime numbers
console.log(product);
This program defines a function isPrime(n) to check if a number is prime using a simple trial division method. It then initializes variables product, count, and num. The program then loops through the first 10 prime numbers, multiplying each prime number by the previous ones to calculate the product. Finally, it prints the product of the first 10 prime numbers, which is 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 = 6469693230.


There is no ads to display, Please add some

Related Post

1. Reforestation Beyond a Single Generation: Sowing for Posterity Discuss the concept of intergenerational reforestation. Explore initiatives that focus on planting trees with a vision for the well-being of future generations, emphasizing the long-term benefits that trees provide. 2. Forest Restoration Ecology: Building Self-Sustaining Ecosystems Delve into the principles of forest restoration ecology. Discuss how reforestation projects aim not only to plant trees but also to establish self-sustaining ecosystems that can thrive and evolve over the long term. 3. Climate Resilience: Trees as Guardians Against Future Challenges Explore the role of reforestation in building climate resilience. Discuss how strategically planted trees contribute to adapting and mitigating the impacts of climate change, ensuring a more stable environment for the future. 4. Biodiversity Conservation: Nurturing a Diverse Tomorrow Highlight the connection between reforestation and biodiversity conservation. Explore initiatives that focus on planting a variety of tree species to create habitats and ensure the survival of diverse flora and fauna in the long run. 5. Legacy Tree Planting: Trees That Stand the Test of Time Discuss the concept of planting legacy trees. Explore initiatives that prioritize the planting of long-lived tree species, creating a lasting legacy that will provide ecological benefits for many decades to come. 6. Watershed Management: Safeguarding Water Resources for Tomorrow Explore how reforestation contributes to watershed management. Discuss initiatives that strategically plant trees to protect water sources, ensuring a sustained supply of clean water for future generations. 7. Forest Education Programs: Cultivating Environmental Stewardship Highlight the importance of forest education in reforestation projects. Discuss programs that aim to cultivate environmental stewardship, ensuring that future generations are aware of the value of forests and their role in sustainability. 8. Indigenous Wisdom in Reforestation: Preserving Cultural Heritage Explore the incorporation of indigenous wisdom in reforestation projects. Discuss initiatives that respect and integrate traditional knowledge, preserving cultural heritage and ensuring the sustainability of reforested areas. 9. Adaptive Strategies: Planting Trees for an Ever-Changing World Discuss the need for adaptive strategies in reforestation. Explore how planting trees that can adapt to changing environmental conditions ensures the long-term success and resilience of reforested landscapes. 10. Global Collaboration for a Sustainable Future: Reforestation Networks Conclude by emphasizing the importance of global collaboration. Discuss how international networks and collaborations in reforestation contribute to a sustainable future, creating a collective effort to address global environmental challenges.1. Reforestation Beyond a Single Generation: Sowing for Posterity Discuss the concept of intergenerational reforestation. Explore initiatives that focus on planting trees with a vision for the well-being of future generations, emphasizing the long-term benefits that trees provide. 2. Forest Restoration Ecology: Building Self-Sustaining Ecosystems Delve into the principles of forest restoration ecology. Discuss how reforestation projects aim not only to plant trees but also to establish self-sustaining ecosystems that can thrive and evolve over the long term. 3. Climate Resilience: Trees as Guardians Against Future Challenges Explore the role of reforestation in building climate resilience. Discuss how strategically planted trees contribute to adapting and mitigating the impacts of climate change, ensuring a more stable environment for the future. 4. Biodiversity Conservation: Nurturing a Diverse Tomorrow Highlight the connection between reforestation and biodiversity conservation. Explore initiatives that focus on planting a variety of tree species to create habitats and ensure the survival of diverse flora and fauna in the long run. 5. Legacy Tree Planting: Trees That Stand the Test of Time Discuss the concept of planting legacy trees. Explore initiatives that prioritize the planting of long-lived tree species, creating a lasting legacy that will provide ecological benefits for many decades to come. 6. Watershed Management: Safeguarding Water Resources for Tomorrow Explore how reforestation contributes to watershed management. Discuss initiatives that strategically plant trees to protect water sources, ensuring a sustained supply of clean water for future generations. 7. Forest Education Programs: Cultivating Environmental Stewardship Highlight the importance of forest education in reforestation projects. Discuss programs that aim to cultivate environmental stewardship, ensuring that future generations are aware of the value of forests and their role in sustainability. 8. Indigenous Wisdom in Reforestation: Preserving Cultural Heritage Explore the incorporation of indigenous wisdom in reforestation projects. Discuss initiatives that respect and integrate traditional knowledge, preserving cultural heritage and ensuring the sustainability of reforested areas. 9. Adaptive Strategies: Planting Trees for an Ever-Changing World Discuss the need for adaptive strategies in reforestation. Explore how planting trees that can adapt to changing environmental conditions ensures the long-term success and resilience of reforested landscapes. 10. Global Collaboration for a Sustainable Future: Reforestation Networks Conclude by emphasizing the importance of global collaboration. Discuss how international networks and collaborations in reforestation contribute to a sustainable future, creating a collective effort to address global environmental challenges.

There is no ads to display, Please add some