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

Chapter 4 Relational Algebra

Relational Algebra The part of mathematics in which letters and other general symbols are used to represent numbers and quantities in formula and equations. Ex: (x + y) · z = (x · z) + (y · z). The main application of relational algebra is providing a theoretical foundation for relational databases, particularly query languages for such databases. Relational algebra...

Chapter 3 Components of the Database System Environment

Components of the Database System Environment There are five major components in the database system environment and their interrelationships are. Hardware Software Data Users Procedures Hardware:  The hardware is the actual computer system used for keeping and accessing the database. Conventional DBMS hardware consists of secondary storage devices, usually...