Spirituality average of first 10 prime numbers using javascript

average of first 10 prime numbers using javascript

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

let count = 0; // Counter for number of primes found
let sum = 0; // Running total of prime numbers
let i = 2; // Start searching for primes from 2

while (count < 10) {
if (isPrime(i)) {
count++; // Increment counter
sum += i; // Add prime to running total
}
i++; // Move on to next number
}

// Calculate average of the first 10 primes
const average = sum / count;

console.log(`The average of the first 10 prime numbers is ${average}.`);
When you run this program, it will output the following result:

csharp
Copy code
The average of the first 10 prime numbers is 12.9.
Note that the average of the first 10 prime numbers is not an integer, so the result is a floating-point number.


There is no ads to display, Please add some

Related Post

1. Deforestation’s Silent Symphony: Acknowledging the Loss Discuss the metaphorical silence left by deforestation. Introduce the idea that reforestation is the process of composing a new symphony, addressing the environmental losses caused by deforestation. 2. The First Note: Initiating Reforestation Projects Explore the first notes of the symphony – the initiation of reforestation projects. Highlight successful examples where the planting of the first trees marked the beginning of a transformative journey. 3. Diverse Instruments: The Role of Different Tree Species Discuss the diversity of instruments in the symphony, representing the variety of tree species planted. Showcase success stories where the careful selection and planting of diverse species contributed to the richness of the reforested landscapes. 4. Rhythm of Growth: Monitoring Progress Over Time Explore the rhythm of growth in the reforestation symphony. Discuss how ongoing monitoring of planted areas reveals the progress of saplings turning into mature trees, creating a rhythm of renewal. 5. Community Engagement: Harmony of Local Involvement Highlight the harmonious contribution of community engagement. Showcase success stories where local communities actively participated in reforestation efforts, creating a sense of harmony and shared responsibility. 6. Wildlife Serenade: Creating Habitats for Fauna Discuss the wildlife serenade produced by reforestation. Explore success stories where the planting of trees has created habitats for various fauna, contributing to the resurgence of biodiversity. 7. Global Crescendo: International Collaboration for Impact Explore the global crescendo in the reforestation symphony. Discuss success stories of international collaboration, where countries and organizations joined forces to create a harmonious impact on a global scale. 8. Economic Harmony: Prosperity Through Sustainable Practices Discuss the economic harmony produced by reforestation projects. Showcase success stories where sustainable forestry practices have not only contributed to environmental renewal but also brought economic prosperity to local communities. 9. Resilient Refrains: Overcoming Challenges with Adaptability Explore the resilient refrains within the reforestation symphony. Discuss success stories where projects overcame challenges through adaptability and resilience, demonstrating the ability of reforested areas to withstand adversity. 10. Symphony of Recognition: Celebrating Reforestation Achievements Conclude by celebrating the symphony of recognition for reforestation achievements. Highlight success stories that have received acknowledgment and awards, showcasing the transformative impact of these projects on both local and global levels.1. Deforestation’s Silent Symphony: Acknowledging the Loss Discuss the metaphorical silence left by deforestation. Introduce the idea that reforestation is the process of composing a new symphony, addressing the environmental losses caused by deforestation. 2. The First Note: Initiating Reforestation Projects Explore the first notes of the symphony – the initiation of reforestation projects. Highlight successful examples where the planting of the first trees marked the beginning of a transformative journey. 3. Diverse Instruments: The Role of Different Tree Species Discuss the diversity of instruments in the symphony, representing the variety of tree species planted. Showcase success stories where the careful selection and planting of diverse species contributed to the richness of the reforested landscapes. 4. Rhythm of Growth: Monitoring Progress Over Time Explore the rhythm of growth in the reforestation symphony. Discuss how ongoing monitoring of planted areas reveals the progress of saplings turning into mature trees, creating a rhythm of renewal. 5. Community Engagement: Harmony of Local Involvement Highlight the harmonious contribution of community engagement. Showcase success stories where local communities actively participated in reforestation efforts, creating a sense of harmony and shared responsibility. 6. Wildlife Serenade: Creating Habitats for Fauna Discuss the wildlife serenade produced by reforestation. Explore success stories where the planting of trees has created habitats for various fauna, contributing to the resurgence of biodiversity. 7. Global Crescendo: International Collaboration for Impact Explore the global crescendo in the reforestation symphony. Discuss success stories of international collaboration, where countries and organizations joined forces to create a harmonious impact on a global scale. 8. Economic Harmony: Prosperity Through Sustainable Practices Discuss the economic harmony produced by reforestation projects. Showcase success stories where sustainable forestry practices have not only contributed to environmental renewal but also brought economic prosperity to local communities. 9. Resilient Refrains: Overcoming Challenges with Adaptability Explore the resilient refrains within the reforestation symphony. Discuss success stories where projects overcame challenges through adaptability and resilience, demonstrating the ability of reforested areas to withstand adversity. 10. Symphony of Recognition: Celebrating Reforestation Achievements Conclude by celebrating the symphony of recognition for reforestation achievements. Highlight success stories that have received acknowledgment and awards, showcasing the transformative impact of these projects on both local and global levels.

There is no ads to display, Please add some

1. Sustainable Forestry Practices: A Holistic Approach Discuss the principles of sustainable forestry practices. Explore how responsible logging, selective harvesting, and ecological restoration contribute to maintaining the health and resilience of timberlands over time. 2. Regenerative Harvesting: Minimizing Impact on Ecosystems Highlight the concept of regenerative harvesting. Discuss how innovative logging techniques can minimize environmental impact, allowing for the regeneration of harvested areas and promoting the overall health of timberlands. 3. Timber Certification Programs: Ensuring Responsible Management Explore the role of timber certification programs in promoting sustainability. Discuss initiatives like the Forest Stewardship Council (FSC) and how they set standards for responsible forest management, ensuring that timberlands are harvested and reforested responsibly. 4. Reforestation as Integral: Balancing Harvest with Planting Emphasize the importance of reforestation as an integral part of sustainable timberland management. Discuss how balancing harvest activities with active tree planting ensures the continuous regeneration of forests, maintaining biodiversity and ecosystem services. 5. Agroforestry Integration: Diversifying Land Use for Sustainability Discuss the integration of agroforestry practices in timberlands. Explore how combining tree cultivation with agricultural activities contributes to diversified land use, enhancing the ecological and economic sustainability of timberland areas. 6. Selective Logging Techniques: Minimizing Impact on Forest Structure Highlight the use of selective logging techniques. Discuss how carefully choosing which trees to harvest preserves the structural integrity of the forest, minimizing disruption to ecosystems and facilitating natural regeneration. 7. Monitoring and Adaptive Management: Keys to Sustainable Harvest Emphasize the importance of monitoring and adaptive management in sustainable timberland practices. Discuss how ongoing assessments help adjust management strategies, ensuring that harvest rates align with the natural regeneration capacity of the forest. 8. Ecosystem Services Recognition: Valuing Beyond Timber Explore the recognition of ecosystem services provided by timberlands. Discuss how sustainable forestry practices consider the broader benefits of forests, including water regulation, soil conservation, and habitat preservation. 9. Community Involvement: Fostering Responsible Timberland Stewardship Highlight the role of local communities in responsible timberland stewardship. Discuss how involving communities in decision-making processes and benefit-sharing fosters a sense of responsibility and ensures the sustainable management of timberlands. 10. Global Collaboration for Sustainable Timberlands: Shared Responsibility Conclude by emphasizing the importance of global collaboration. Discuss how international cooperation in promoting sustainable forestry practices ensures a shared responsibility for the conservation and regeneration of timberlands on a global scale.1. Sustainable Forestry Practices: A Holistic Approach Discuss the principles of sustainable forestry practices. Explore how responsible logging, selective harvesting, and ecological restoration contribute to maintaining the health and resilience of timberlands over time. 2. Regenerative Harvesting: Minimizing Impact on Ecosystems Highlight the concept of regenerative harvesting. Discuss how innovative logging techniques can minimize environmental impact, allowing for the regeneration of harvested areas and promoting the overall health of timberlands. 3. Timber Certification Programs: Ensuring Responsible Management Explore the role of timber certification programs in promoting sustainability. Discuss initiatives like the Forest Stewardship Council (FSC) and how they set standards for responsible forest management, ensuring that timberlands are harvested and reforested responsibly. 4. Reforestation as Integral: Balancing Harvest with Planting Emphasize the importance of reforestation as an integral part of sustainable timberland management. Discuss how balancing harvest activities with active tree planting ensures the continuous regeneration of forests, maintaining biodiversity and ecosystem services. 5. Agroforestry Integration: Diversifying Land Use for Sustainability Discuss the integration of agroforestry practices in timberlands. Explore how combining tree cultivation with agricultural activities contributes to diversified land use, enhancing the ecological and economic sustainability of timberland areas. 6. Selective Logging Techniques: Minimizing Impact on Forest Structure Highlight the use of selective logging techniques. Discuss how carefully choosing which trees to harvest preserves the structural integrity of the forest, minimizing disruption to ecosystems and facilitating natural regeneration. 7. Monitoring and Adaptive Management: Keys to Sustainable Harvest Emphasize the importance of monitoring and adaptive management in sustainable timberland practices. Discuss how ongoing assessments help adjust management strategies, ensuring that harvest rates align with the natural regeneration capacity of the forest. 8. Ecosystem Services Recognition: Valuing Beyond Timber Explore the recognition of ecosystem services provided by timberlands. Discuss how sustainable forestry practices consider the broader benefits of forests, including water regulation, soil conservation, and habitat preservation. 9. Community Involvement: Fostering Responsible Timberland Stewardship Highlight the role of local communities in responsible timberland stewardship. Discuss how involving communities in decision-making processes and benefit-sharing fosters a sense of responsibility and ensures the sustainable management of timberlands. 10. Global Collaboration for Sustainable Timberlands: Shared Responsibility Conclude by emphasizing the importance of global collaboration. Discuss how international cooperation in promoting sustainable forestry practices ensures a shared responsibility for the conservation and regeneration of timberlands on a global scale.

There is no ads to display, Please add some