C program to sum of all prime numbers in 1 to 100.

Interview Programming

Prime Number:

A positive number whose divisors only 1 and the number itself (among all the positive numbers) are known as prime number.

Example: 1,2,3,5,7,11.

Among positive even  number only 2 is the prime number rest of all the prime numbers are odd(positive) number.

 

#include<stdio.h>
int main()
{
int number,i,j,primeNumber,low=1,high=100,sum=0;
printf(" Sum of Prime Numbers : \n");
for(j=low;j<=high;j++){
primeNumber=0;
for(i=2;i<=j/2;i++){
if(j%i==0){
primeNumber++;
break;
}
}
if(primeNumber==0 && j !=1)
sum +=j;
}
printf("%d\t ",sum);
return 0;
}

output:

Sum of Prime Numbers :

1060

0 Comments

You may find interest following article

Complete Guide: Create Laravel Project in Docker Without Local Dependencies

Create Laravel Project Through Docker — No Need to Install PHP, MySQL, or Apache on Your Local Machine In this tutorial, I’ll show you how to create and run a full Laravel project using Docker containers. That means you won’t have to install PHP, MySQL, or Apache locally on your computer. By the end of this guide, you’ll have a fully functional Laravel development...