Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this program finds all the prime numbers betwen 0 and 101
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- #include <stdio.h>
- using namespace std;
- int main ()
- {
- int num, divisors, prime=0, count, three, sum, rest;
- for (num=0; num<=101; num++){ // this for loop finds the sum of all numbers between 1 to 101.
- sum=sum+num;
- }
- cout << "This code will show the sum of all integers from 0 to 101: They are " << sum << endl;
- for (num=0; num<=101; num++){ // this for loop finds all the sum of all multiples of three.
- if (num%3<1){
- three=three+num;
- }
- }
- cout << "This code will find and display of sum of all multiples of three from 0 to 101: They are " << three << endl;
- for (num=0; num<=101; num++){ // this loop finds the sum of all prime numbers between 1 and 101.
- if (num>1){
- count=num;
- }
- for (divisors=2; divisors<num; divisors++){
- rest=num%divisors;
- if (rest<1){ // this is the if statement that makes the added value 0 if the tested number has anny divisors.
- count=0;
- }
- }
- prime=prime+count;
- }
- cout << "This will display the sum of all primes from 0 to 101: they are " << prime << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement