Find The Sum of Prime Numbers Between 1 to 1000

C Program to find the sum of prime numbers between 1 to 1000

//This code is written by Souvik Ghosh
#include <stdio.h>
int primeChecker(int num)
{
 int flag = 0;
 if (num == 1 || num == 0)
    {
 return flag = 1;
    }
 else
    {
 for (int i = 2; i < num; i++)
        {
 if (num % i == 0)
            {
 flag = 1;
            }
        }
    }
 return flag;
}
void main()
{
 int sum = 0;
 for (int i = 1; i <= 1000; i++)
    {
 if (primeChecker(i) == 0)
        {
 sum += i;
        }
    }
 printf("Sum of the prime numbers betweeen 1 to 1000 is %d\n", sum);
}
/*
1 is neither prime nor composite because prime number has two positive factors but one has only one positive factor
i.e. 1 itself and it is not composite because composite number has more than two positive factors but 1 has only one
positive factor.  
*/

Related Posts

CSS Cheatsheet

Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…

HTML Cheatsheet

Unleash your web development potential with my HTML cheatsheet! Elevate your coding skills, master essential tags and attributes, and build stunning websites with ease. Whether you’re a…

Git&GitHub Cheatsheet

Elevate your Git and GitHub game with my ultimate cheatsheet! Unlock the power of version control, streamline collaboration, and boost productivity. Navigate the complexities of Git commands…

Command Line Cheatsheet

Master the Command Line effortlessly with my comprehensive cheatsheet! Streamline your workflow, boost productivity, and become a command line guru. Unlock essential commands, shortcuts, and tips to…

OpenAI’s APIs Notes

Unlock the potential of OpenAI’s APIs with my comprehensive notes! Dive into the world of cutting-edge artificial intelligence, explore the capabilities of GPT-4 and beyond, and learn…

SQL Notes

Discover the essence of SQL with my comprehensive notes! Dive into the world of Structured Query Language, unraveling the complexities, and mastering database management. Elevate your SQL…

Leave a Reply

Your email address will not be published. Required fields are marked *